PHP bashing is trendy
I’ve seen quite a few links bashing PHP lately. I haven’t been pointing out PHP’s flaws myself, because that would just detract from me complaining about how much Coldfusion sucks ;) Luckily from the end of the month I won’t have to deal with Coldfusion anymore, so I can jump on the PHP bashing bandwagon again.
There are some relevant links here, here and here. I’m going to attempt to add to that and hopefully my arguments won’t be too muddled.
I’m not going to try and convince anyone to shift over to the other extreme (Java or .NET) because I’m a great fan of dynamic languages - I prefer Python to Ruby purely because of aeshetic reasons, but both of them have some good frameworks and libraries to help with web development. Most of it only came out in the past year or two. For Python there is (among others) Django and Turbogears, for Ruby there is Ruby On Rails. No single framework will work for all types of projects and maybe you should rather just use some libraries, but that’s a separate discussion altogether.
Magic Quotes, Register Globals and other incompatibilities
The magic quotes setting really is a pain. You cannot just set the ini setting inside your script, because by then it already did the damage. If you use a database engine that requires values escaped differently (postgresql or sqlite, for example), then you have to unescape everything (if magic quotes is on) and then escape the values again.
register_globals is a minor annoyance. Anyone with a brain will develop code with register_globals off, but you never know what will happen when your code gets deployed on someone elses server that’s got it turned on.
The fact that they sometimes make big changes between minor versions is really bad as well. 4.x.2 might not even be backwards compatible with 4.x.1 and by the time you reach 4.y.0 everything breaks, only for half of everything to be changed back to the way it was by the time they reach 4.y.3.
Sure you can code around all of this, but you really shouldn’t have to. The fact that PHP can differ so much between different minot versions, servers and deployments makes development and testing a lot more difficult than it should be.
Error handling
The fact that by default PHP just continues on errors and guesses values for things that are not defined, etc. is absolutely terrible. This is usually the first thing I disable and try and protect against. I usually try and catch absolutely any error, warning or notice and (if it is a development server) rather crash as loudly as possible, but this is actually a lot harder and less obvious than it should be. I’ve seen catastrophic things happen because (for example) two bits of string got appended together, the second variable wasn’t defined, PHP decided to use a blank string and this string then later formed part of a file path.
To add to the annoyance, there’s no proper/standard way for errors to be reported and handled. I really prefer exceptions and stack traces with as much debugging and context-related info as possible. You know - what any decent modern language and framework provides. Programming in an environment that doesn’t have good exception handling (try and except) can be very painful once you’re used to it. This is probably a bit off topic, but I really miss introspection and an interactive interpreter as well.
Suitability to other types of programming
PHP is only suited (argueably, at least) for writing scripts that run inside a webserver. In my experience, most systems usually require some other types of programming like some cron jobs, import and export of data, automated testing, debugging and analysis, maybe some services/daemons, etc. PHP is definitely not well suited for any of those.
This might not be relevant to everyone or even most people, but I ended up writing a big chunk of a system in some other language on more than one occasion. This meant that I couldn’t reuse any of my code and it introduced more dependencies and generally just more things that can break.
Shared nothing
PHP’s “shared nothing” style is probably a good thing in that it is safe for people that aren’t really programmers, but it is definitely not always the best solution. In fact, it seldom is. I really miss an application scope where things that don’t need to be retrieved or calculated on every request can live. It is often a serious problem how everything you need gets loaded up, included, compiled, etc. on every request. Yes there are accellerators that cache templates, but they are workaround and don’t fix the underlying problem in my opinion.
Ugly urls by default
PHP is still a lot like CGI which effectively maps urls to files. Urls that end with .php?a=1&b=2, etc are ugly and they tie things to the underlying implementation language. What if you rewrite your site in a different language one day? Then you have all those incorrect links to your content lying all over the web. You can get around this by using mod-rewrite or something similar, but in my opinion it often locks people into a “urls point to files” instead of “urls point to resources” way of thinking which is inhibiting imho.
The language and libraries suck ass
I read how someone once said that PHP syntax looks like the result of a drunken alley fondle between c and Perl. That’s a pretty accurate description in my opinion.
Similar to the way I see asp and Coldfusion, PHP started as a kind of template engine where things like database connectivity and some (slightly) more powerful programming concepts got added bit by bit later without any vision or attempt to work towards some consistent goal. The result is that it doesn’t have all the cool language features the other popular dynamic languages (Python and Ruby) have and the naming style of functions and things are as inconsistent as… I can’t even think of an analogy. That means you constantly have to refer to the documentation for things that really should be intuitive.
The builtin data types are just weird, no nice design patterns like iterators, no concept of convention in general, scoping is just plain terrible, etc.
PHP 5
PHP 5 fixes some of these things (but not the most important ones), but is so incompatible with PHP 4 that it really should just be treated as learning a new language. And as far as learning a new language goes, you can do much better.
Leave a Response