logo - blitzware
blitzware.com - new technology review

PHP 5 at Work

By Zeev Suraski

PHP is one of the most popular web platforms in the world, surpassing platforms such as ASP and JSP that are backed by giant corporations. The recently released version 5 marks a new era for PHP. Not only did the best tool for the job get better, but it includes quite a few features that computer science zealots will find cool.

PHP 5 is actually the third incarnation of the language—the initial version was released as version 3 in order to make it clear that it succeeds and replaces the old PHP/FI 2, from which some ideas were borrowed.

Zend Engine II: Object Model Reloaded

One of the popular legends in the PHP world is that the PHP object model was nothing but the result of a single sleepless night of one of its authors, who thought it would be nice to be able to access arrays using C's arrow notation (foo->bar). Unfortunately, there's truth to this rumor.

When objects were introduced to one of the early language betas, circa 1997, they were virtually indistinguishable from arrays. In fact, one could use arrays as objects and vice versa interchangeably. While this fact had its upsides (mainly allowing people to use a cool-looking operator), it mostly came bundled with a lot of downsides. For one, objects behaved like any other native type in PHP, and more specifically, objects were passed around, to and from functions, by value. Secondly, due to the shared implementation with arrays, no object-specific features (such as access restrictions, type checking, etc.) were available.

The situation remained largely unchanged for six years, until now.

PHP 5 is based on the Zend Engine II, which in turn contains a completely new object model. At first glance, the new model may remind you of that of Java. This impression may stick for the second and third glance, and is actually likely to stay forever. Like Java, the Zend Engine II's object model is handle based, which effectively means that passing around an object—whether sending it to a function, or returning it from one—is going to result in the object itself being passed, rather than a copy.