I was working on a small project this week that reminded me again of PHP’s fatal flaw, which is that it is nearly impossible to maintain encapsulation to prevent components of a system from screwing each other up. We have a Web site that uses a big, popular, open source PHP application. The home page of the site loads up some components of the system and displays some information. I had written a tiny application to enable users to maintain one small section of the home page. My application’s involvement with the home page consisted of one function and one callout to the function to display its return value. The function was basically this:
function getQuote() { $my_db = mysql_connect(“host”, “user”, “password”); mysql_select_db(“my_db”, $my_db);
// Query the database, grab a value, and return it. }
My code worked fine, but the mysql_select_db
call blew up the other application. As far as I can tell, everything I did should live within the local namespace of my function and shouldn’t affect anything else on the page. To fix the problem, I wound up writing my function using mysqli. I’m not sure if that worked because mysqli provides better encapsulation or because the rest of the application uses the old style MySQL functions and the newer mysqli stuff doesn’t conflict with it.
Aside from the pain in dealing with problems like this, I think that PHP’s lack of clean encapsulation is probably what makes many PHP applications tend toward chaos as they grow.
Zero day tracks
The fact that Paul McCartney’s new album, Memory Almost Full is available from emusic.com in DRM-free MP3 format on the day of its release feels like a very big deal to me.