Yes, yes, I admit the herasy; I like PHP. No, no, PHP has tons of worts with it, so no, it’s not better that alternative X, Y or Z for task Q, W or E. I hate comparing languages this way, feature by feature, syntax by semantics, and so on. I like to judge languages on two things;
I really like the CGI style for web resources. No, PHP ain’t CGI (unless you’re in a pain-self-inflicting mood) but most often a glorious Apache module which reuse all the goodness it can offer, but the model of a totally independent scripting engine which needs to mold its relationships, and then you throw it away when you’re done, makes for a clean, fast and very scalable framework. PHP basically compiles together mostly C modules, and use its simple syntax to glue stuff together. Yes, there’s a backlog of really shitty and badly written code out there, especially when people have no clue. And when the threshold is as low as it is for PHP, that’s inevitable, but I hardly hold that against the language itself. The environment in which that shitty code runs is really good. To me, the environment is the best part of PHP. Perl falls somewhat into this same category.
For those in the know, this model is very similar to how a RESTful system works, where the interpreter is a manifestation of a resource. In resource-oriented development this means gold, and is very important to me as my environment supports my RESTful way of designing systems.
And since style is something any good developer can control themselves (unless their language is super-strict), this really is the main thing that I like about PHP; It gives me the freedom to make things work for me. I can choose the methodology, whether a function, class or inline is best suited, and since PHP always is evaluated in run-time, I can make my environment depend on real-time parameters rather than a pre-compiled utopia.
I’ve been using the Zend Framework for the last year or so, and it’s a great framework as such, although the focus has been mostly to put OO wrappers around common PHP idioms and conventions. As such it works great to perhaps consolidate the features, and perhaps give PHP 6 a future direction. This is the best part of the Zend Framework.
The bad thing about the Zend Framework is that it imposes its own style, and somewhat alters the environment. Ouch, on both the things that make PHP my choice tool. I’ve struggled quite a bit in trying to reuse certain parts of the framework, extend others, and generally use some bits without using the whole shebang. There’s not a lot of dependencies between the components, but just enough to make it tricky to do serious stuff (for example writing an alternative “threads-like” HTTP adapter to HTTP Request).
Now, people talk about the Zend Frameworks impact on the future of the PHP language. Yes, one can always hope that this is the case, but I think people are a little too preoccupied with the OO capabilities and forgetting perhaps what makes PHP really popular with those who choose to continue to use it past their first few applications. Do not fall into the trap thinking OO is somehow better than other ways.
As much as people think MVC is the best thing, I really don’t care about that. MVC works great for some things, not for all (for example, I have a REST framework that use a completely different model, a more resource oriented model), so to impose MVC as the modus operandi is not good, and indeed something that makes reuse of other ZF modules a bit trickier. Instead of a MVC focus, there should be a strong highlighting of a uniform interface to the environment itself. It’s the environment that’s cool with PHP, so let’s make interfacing to that better. There’s some work on wrappers and readers for various aspects of the HTTP protocol, but only the most basic stuff is in there and needs serious work. With PHP I could do serious HTTP applications; with Zend Framework I’m limited, and need to hack and extend. Let’s get HTTP savvy, not MVC drones.
Availability and diversity
PHP is everywhere. Period. I can use pretty much any ISP or in-house hosting to host most of what I need. And there are so many different open-source projects about that uses PHP (WikiPedia, WordPress, PHPBB, PHPMyAdmin, Drupal, Joomla, Flickr … the list goes on) meaning both hosting and the amount of high-quality tools are abundant. The LAMP stack is pretty much supported on every hardware and software platform. Heck, I can even run it on the JVM.
I have written many tools over the years, some good, some bad, but I’m always happy to find out that I can copy my old files into any new environment and they will pretty much always run straight away, no tweaking. I can’t tell you how important this is!
The shitty stuff
No system is perfect, to some specific definition of what “perfect” means. With PHP, I’ve learned to live with its odd bits, such as funny booleans and comparators, diverse and non-uniform APIs, sloppy exception handling, no shared memory (which may or may not be a good thing, but certainly a big part of its design), and a few syntactic snuffs (Why not introduce “$$” as a shortcut for “$this->”, for example? Tidbits).
Some say that PHP code is crap, usually said when encountering – indeed! – shitty code. But shitty code is everywhere. Even in the most tied-down, static and controlled environments you still get shit. Some say less shit. I say shit with a different color, not different odor. I’ve been programming for almost 30 years soon, and let me tell you, I’ve encountered shitty code in every single environment and language I’ve ever tried, and I’m one of those who tries every language out there. There is no language who can hold a stick to the wonderful imaginitive mind of man, able to lay bricks where diamonds should have shone.
Some say the PHP language itself is immature, or unstructured, or some other parameter that their favourite language holds. No, sorry, but there’s not that much which separates all our different languages (except BrainFuck … that one is seriously different. :), and indeed a lot of the language wars are really more about their API designs than the languages themselves. For example, the syntax of Java is tolerable, but a lot of its APIs are not. The syntax of Python is ok, but some of its APIs are great. Ruby has good syntax, but to me some confusing APIs.
It’s really mostly about APIs, and how we create models to solve our problems. It’s all about models, as APIs in themselves are models. The API is not the language.
I should here of course mention the link between models and Topic Maps, as the latter is a way to define, work with and exchange / share the former. Couple this model openness with resource-orientation, and I think it makes for a very interesting environement. But as this whole shebang is part of the new framework I’m working on, expect more blogging on this in the very near future. Have a wonderful week.