The Bug Is In Your Code
I stumbled across this while reading some tweets: http://bugs.php.net/bug.php?id=52198. This reminded me of something I was told while attending a programming workshop at college: over 90% of the time the bug is in your code. At the time I didn't think about this much as I had been writing code for only about 6 months and assumed the third party libraries I was using were bug free. As I continue to grow as a developer and engineer, I am amazed at the number of developers immediately blaming the library or framework they are using for a bug in their project. Bugs do exist in all code, but it is more likely that the bug is in your code.
PHP 5.3 is the new JavaScript (almost)
In my last post, I argued that the best way to start developing functional PHP applications was to code review some JavaScript projects. I think this is a good place to start as most web developers have written some JavaScript at one point during their career. I briefly mentioned that the array is pretty similar to the JavaScript object too. However, if you start hacking away at PHP based on JavaScript's functional syntax, you will quickly run into some problems.
PHP goes functional in version 5.3
It has been said that all languages, over time, implement a dialect of lisp. PHP appears to be no exception.
Mocking Zend Framework’s Row and Rowset objects
If you separate your business logic from your data access logic, the last thing you want to do is make your business logic unit tests reliant on the database. This is normally not a big deal: retrieve the data, store it in an array and pass it off to the class with the business logic. Mocking the data for the unit test simply requires you to hardcode from array information in the test. However, I recently ran into a case where I wanted to pass Zend_Db_Table_Row and Zend_Db_Table_Row objects to the business logic and mocking them was not so easy.
Logging Exception Traces To syslog
If you have ever visited StackOverflow.com you may have noticed the ads for Splunk. Splunk aggregates log files together and provides a web interface to search through those logs. The setup for php is easy: set the php.ini error_log value to "syslog". The Splunk instructions show you how add a single line to your syslong.conf to have syslog send those messages over to Splunk.
Unit Testing and the Law of Demeter
I was writing some code today and not using Test-Driven development. The reason was that I did not have a good understanding of what I was writing, so I decided to write some of the guts before writing the tests. In the process of writing the guts, I recognized that I was paying very close attention to how I was going to later test each of the methods I was writing. I was paying especially close attention to the Law of Demeter. The idea behind the Law of Demeter is to keep units of code distinct from one another. So how did this relate to my code? To put it simply, my business logic methods did not use get methods.
Facebook Thrift PHP Client
A while back I wrote a post about using Facebook's Thrift. One comment asked me to post the PHP client used to connect to the C++ server I was demo'ing. Most of the client is boiler-plate code generated by Thrift, so I chose to omit it at the time. Here it is:
Speaking at Jan. 20th LA LAMP meetup
I will be giving a short presentation on HauteLook's architecture at the LA LAMP meetup on January 20th. I have been meaning to join a user group for some time, so this worked out perfectly. Any developers in the LA area on that day should come, even if it is just for the free food and beer.
Phing – phplint task
Phing is a PHP port of Java Ant. It is a great tool to use in development. It standardizes a lot of build scripts you would have to maintain internally. Unfortunately, examples seem to be lacking. As a quick introduction to Phing, I will show how you can check all your php scripts for syntax errors.
Zend_Soap_AutoDiscover and eAccelerator
The Zend Framework ships with SOAP functionality and one especially neat class called Zend_Soap_AutoDiscover.
This class uses a comment docblock to auto-generate a WSDL at runtime. I won't go into the details how it works here, but you can check the Zend Framework documentation for an example. When using this class at work, I noticed the WSDL would not always generate correctly. After a lot of digging around, I found the cause: eAccelerator.