Why does anyone use PHP for anything?

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

I was a fanatic proponent of PHP, back around 2000. If I wanted to build a website, I could use Java or Perl or PHP. The choice was straightforward. Java was complex, and any change demanded that the code be recompiled. Perl had a small core and a million libraries that you needed to bundle in, so it was a little bit like Java in that you had to assemble a lot of different pieces. PHP was a light weight, dynamic scripting language that came with a huge core library that had everything you would ever want (or was available in the standard builds that came on most hosting servers). If you made a change to the code, you would just hit “refresh” in your browser and you could see the change. If you were building websites, the obvious choice was PHP.

The world has changed. The JVM now has dozens of languages that are lightweight and dynamic, there are build environments for the JVM that support the hot-loading of new code, and even compiling code is faster. Also, there are fantastic package managers that ensure including 3rd party libraries is no longer the great pain that it once was.

And PHP? Here is the cutting edge in the land of PHP:

To ensure optimal flexibility and code reuse, Symfony2 applications leverage a variety of classes and 3rd party components. But loading all of these classes from separate files on each request can result in some overhead. To reduce this overhead, the Symfony2 Standard Edition provides a script to generate a so-called bootstrap file, consisting of multiple classes definitions in a single file. By including this file (which contains a copy of many of the core classes), Symfony no longer needs to include any of the source files containing those classes. This will reduce disc IO quite a bit.

If you’re using the Symfony2 Standard Edition, then you’re probably already using the bootstrap file. To be sure, open your front controller (usually app.php) and check to make sure that the following line exists:

require_once __DIR__.’/../app/bootstrap.php.cache’;

Note that there are two disadvantages when using a bootstrap file:
the file needs to be regenerated whenever any of the original sources change (i.e. when you update the Symfony2 source or vendor libraries);

when debugging, one will need to place break points inside the bootstrap file.

If you’re using Symfony2 Standard Edition, the bootstrap file is automatically rebuilt after updating the vendor libraries via the php composer.phar install command.

PHP has lost its advantages. Real-world uses of PHP nowadays involve the kind of complexity that I associated with Java in 2000. Worst of all, PHP lacks good package managers. Perhaps because for so long it followed the all-in-one philosophy that everything should be included in the core, PHP has been slow to offer the kind of build/package managers that every other language now has.

Source