…with a list of things that I don’t like about PHP!
I really, really like PHP, and I have a whole lot to say about how great it is and everything else - but some little part of me says: “Hey, who are you to talk about how great PHP is, without first knowing whats bad about it.” and so thats what this first post is about.
PHP attracts a lot of critisism, and some of it is well earned. Much of the critism can be attributed to haters, Java developers, sysadmins burnt by bad coders and recently Ruby fanbois, however if you listen to the PHP community, as well as the more reasonable burnt sysadmins, Ruby fanbois and Java devs, there is certianly a lot there that PHP developers should be aware of.
Piss poor portability
Portability is what PHP does worst. Thankfully I’m an in-house developer working on a system that will, for the most part, never have to run on an unknown PHP config, but I can just imagine the seven circles of hell that developers must have to jump through to get some application to run on the majority of PHP installs. Each version upgrade seems to bring new incompatabilities with the default install - let alone when you consider all the tweaks and configs that different environments might have - PEAR classes, PECL extensions, custom php.ini’s and so on and so forth. I have enough difficulty just trying to keep my development environment the same as my production one!
This is a real issue, as the longer it continues, the slower the uptake of the newer versions of PHP will be. The core developers seem to be taking a lot of care with PHP6 to make sure new stuff is backwards compatible, which is really great but it might be too little too late when you consider how much forum, blog, wiki and CMS there is out there running on PHP4
Namespaces & naming conventions
The lack of namespaces in PHP I could live with, if I never had to use any 3rd party code and never wanted to produce PHP code for others to use. Unfortunatly I do need to use 3rd party code, and occassionally I do have to write something others are going to use or I dont want to add to my collection of EventCategory, FeatureCategory and CommentCategory objects, it would be bliss just to be able to ensure there were going to be no clashes.
PHP’s (lack of) naming conventions are an oft voiced complaint about PHP, and righty so - some of them are hefty namespace kludges (simplexml_element_registerxpathnamespace which can’t decide whether it wants camel caps or underscores) and some of them are just a plain and stupid lack of convention (strpos vs str_replace or nl2br vs strtolower). For the most part this sort of thing doesn’t matter at all, and we can all work with the whacky function names, but it is still a valid critisism.
Low barrier to entry
Catch 22, PHP’s best aspect is also its worst, its easy to write bad code, but its just as easy to write good code too, whats hard is reworking bad code into good code and there is plenty of bad code out there. Thats nothing to complain about, after all, it keeps me in work… but there are some appauling programming practices out there, not because PHP is bad, but because PHP is an easy scripting language to learn, easy to hack something out and get it working, or easy to ‘voodoo’ code some new feature into an existing application.
Anyone with a halfway decent book on PHP & MySQL can create a web application, which is great, and there is a whole lot of example code out there, help and advice on a thousand forums, as well as the inline user contributed notes in the PHP manual.
Eeek!!! What am I saying?
There is a whole world of crappy code out there (and as Theo Schlossnagle pointed out recently, a whole bunch of it is in the PHP manual) and it seems that everyone is an expert, even me nowadays. Unfortunately there isn’t a way of testing to see whether someones advice is good or not and it can be quite difficult to apply an academic Computer Science education to PHP, and a lot of people picking up PHP manuals dont have a traditional CompSci background, and there is a genuine lack of good resources out there for compitent programmers who are new to PHP - so new developers will often learn through trial and error, rather than by applying good practices from the beginning. Its up to those in the PHP community that do know thier stuff to sound off, and make themselves heard above the background noise.
Lack of Unicode support
So many string manipulation functions, and so little support for character encoding. For a scripting language which started out as a viable replacement for perl CGI, PHP does a fantastic job of not giving a damn about how a string is encoded before it goes to work. If you didn’t know, its coming in PHP6, and it can’t come soon enough.
Until then, building support for internationalisation into your apps might be a horrible, painful experience.
Its not all bad, some of PHP’s weaknesses are also some of its biggest strengths, and I’ll go into that in another post soon.