PHP, Be Not Proud

What?Over the years, PHP has been instrumental to progress in the field of web development. As one of the early pioneers of server-side web scripting, the PHP language grew to become the dominant programming language of open-source web applications. Its free and open-source codebase made it the default programming language on Apache and Linux, and the large number of excellent web applications built on PHP will secure its existence for at least the next fifteen years.

After over a decade of programming on PHP, however, my personal fascination with the language is at an end. Odd behavior and strange nuances in language are a standard, however one recently discovered bug puts it over the top. The language treats global variables differently from inside a function:

$BookCount = array('Count of Monte Cristo'=>5,'The Three Musketeers'=>2);
function setBookCount(){
global $BookCount,$curBookCount;
//$curBookCount will not retain a value upon return from the function
$curBookCount = &$BookCount['Count of Monte Cristo'];
echo $curBookCount;

In sum, global variables can’t be set as references from inside a function. Although PHP sets the variable reference properly within the scope of the function, upon return, the variable is reset to null. The bug itself is not a show-stopper, the workaround is to use a copy instead of a reference. However when doing so, both the original variable and the instance are not synchronously updated. When looking through the PHP documentation, even the creators of PHP acknowledge that references are a mess and can cause even more overhead in execution than non-references. The other bugs in PHP could be classified as nuances of the language, however this is a plain and simple error – blatant and reviling in a language that has been in production release for over ten years. Completely inconsistent behavior for such a fundamental primitive as references is not acceptable in any programming language.

PHP……why??? Your language was the first great web platform to simplify nested templating and self-modifying buffers. Much of the rage that is sweeping the web in the past five years was standard in your joyous bosom. Why, given all your resources, all your users, could you not revise your language into something worth fighting for?

The ecosystem of the web abounds with viable competitors waiting to take PHP’s place. The most realistic competitor is Node.js. With a more stable language and faster execution time, there are few reasons not to switch from PHP to Node. The sheer flexibility of Node’s platform enables even greater programming capability than PHP, and a dizzying array of middle-ware helps improve developer productivity by easily leveraging existing components. Given PHP’s continued lack of focus on providing a stable language, and Node’s increasing popularity and capability, it will hopefully be only a matter of time before Node becomes the new de facto language of the web. And at long last, PHP, though shalt be no more. PHP, though shalt die.

Written by Andrew Palczewski

About the Author
Andrew Palczewski is CEO of apHarmony, a Chicago software development company. He holds a Master's degree in Computer Engineering from the University of Illinois at Urbana-Champaign and has over ten years' experience in managing development of software projects.

RSS Twitter LinkedIn Facebook Email

One thought on “PHP, Be Not Proud”

  1. Lol.. Thats Why facebook created their own programming language Hack and their own HHVM and they even tried to compile php to C++ using HipHop

Leave a Reply

Your email address will not be published. Required fields are marked *