Category: Software Development
-
How to generate the Fibonacci sequence with PHP
The Fibonacci sequence is a sequence of numbers that are derived from the previous numbers in the sequence. The sequence starts at zero and each subsequent number is sum of the previous two numbers in the sequence. There are a number of ways to accomplish this and the most common…
-
How to connect to MongoDB using PHP
I’ve previously discussed installing the MongoDB module but have yet to touch on how to actually do anything past the install. The first thing to do is to connect to the MongoDB server. This can simply be done like this: $client = new MongoClient(); This will connect to the default…
-
Stop Accommodating Shortcomings
I came to a very liberating conclusion the other day. I need to stop fucking around with MySQL, or any other RDBMS, and fully embrace a NoSQL server as my primary data store. I’ve been a huge fan of Redis for quite some time but the fact that everything lives…
-
How to merge two sorted PHP arrays without array_merge() or sort()
I’ve had this question come up a few times in the past on interviews, how would you merge two sorted arrays and keep their sort order intact? The easy / PHP answer is to simply use array_merge() and then sort() the resulting array. Technically this works but the whole point…
-
Thoughts on API design
I recently had the opportunity to have a discussion about API design and RESTful services with Vasusen Patil. I’ve also been having quite a few conversations of similar nature with Justin Davis over the last few months. These types of conversations are some of my favorite because, for the most…
-
Visibility in PHP
Visibility of functions and properties is very important when you are attempting to lock down certain aspects of an object. In PHP there are three levels of visibility, public, private and protected. Let’s take a look at what each one means. Public Public is the easy one. It’s the default…
-
Simple PHP i18n internationalization and localization class
As sites and system grow and scale, the need for internationalization and localization (i18n and L10n respectively) of content becomes a necessary task. There’s not much to it on the surface, you need to be able to serve up the same content in different languages. This includes abstracting out words…
-
The definition of “done”
For me, “done” means that something I have been working on is to the point that I no longer have to work on it, indefinitely. Depending on the nature of the task it could also mean that it’s been shipped to production and again, no longer requires my efforts. I…
-
Debugging Invalid XML in PHP
SimpleXML with all of it’s faults is still a great way to interact with XML. Most of it’s shortcomings are related to debugging and how it handles invalid XML is no exception. Let’s take a look at what happens when we load an invalid XML string: $xml = ” <?xml…
-
Writing unit tests for legacy code
I think one of my biggest gripes with adopting that TDD life is that I feel I’m in the minority with my friends even though the concept appears to be quite mainstream these days. One of the common pushbacks I receive is that it’s hard to write unit tests for…