I have planned to start a series of tutorials to cover php5 in all aspects, and i hope it will help me and you with the passage of time. I believe in sharing and have a strong thought that knowledge increases by sharing.  This post is about history and successful entrance of objects in PHP world.

Objects were not always a key part of the PHP project. This post introduces coverage of objects by summarizing the development of PHP’s object-oriented features.

Start of PHP: PHP / F1 2.0

PHP stands for Personal Homepage and F1 stood for Form Interpreter. It was about sending SQL statements to databases, processing forms, and flow control. There was support for variables, associative arrays, and functions. Objects, though, were not even on the horizon.

Next Version: PHP3

The principal architects of PHP 3 were Zeev Suraski and Andi Gutmans. PHP 3 was a complete reborn/rewritten but objects were not deemed a necessary part of the new syntax. Although there were support of classes but classes and objects were actually just another way to define and access associative arrays.

  • There were still severe limitations as to what you could do with your classes
  • You could not access a parent class’s overridden methods

Much Advanced: PHP4

There was rewritten of Zend Engine from scratch to power the language. Zend Engine name is derived from Zeev and Andi. It is the Zend Engine we have to thank for core language features like classes.

As an objective perspective, the fact that PHP 4 made it possible to override parent methods and access them from child classes was a major benefit. A major drawback remained, however. Assigning an object to a variable, passing it to a function, or returning it from a method, resulted in a copy being made. So an assignment like this,

$obj1 = new User('life');
$obj2 = $obj1;

resulted in the existence of two User objects, rather than two references to the same User object. In most object-oriented languages you would expect assignment by reference, rather than by value as here. This means that you pass and assign handles that point to objects rather than copy the objects themselves. This pass-by-value behavior may lead to,

  • It can be resulted in many obscure bugs as programmers unwittingly modified objects in one part of a script.
  • It was all too easy for bugs to creep into object-oriented code.
  • These were particularly hard to track down, because they rarely caused any reported errors, just plausible but broken behavior.

A Revolution: PHP5

PHP 5 represented an explicit endorsement of objects and object-oriented programming. Objects are, however, now recognized as a powerful and important means for developing enterprise systems, and PHP fully supports them in its core design. Objects have moved from afterthought to language driver. Following are some important changes that extend and enhance PHP’s object support

  • The most important change is the default pass-by-reference behavior in place of the evils of object copying
  • Argument hinting
  • Private and Protected methods and properties
  • The “static” keyword
  • Namespaces
  • Exceptions

PHP remains a language that supports object-oriented development, rather than an object-oriented language.

My Views

Many excellent programmers have produced excellent code for years without using objects, and PHP continues to be a superb platform for procedural web programming. The future for PHP is very much bound up with object-oriented design.