Limitations of Object-oriented Programming in PHP

We indicated already a few times that the implementation of OOP in PHP is actually not a fully-fletched OOP

since several concepts of object-oriented programming of other languages like C++ or Java are implemented in PHP only rudimentary or not at all. In the following we would like to cater to several of those missing OOP properties and the consequences briefly.

  1. No private variables and functions, only public ones
    Already mentioned at the beginning: There is no possibility to define within a class which variables and functions shall be public and which non-public. Through this an access from outside is possible in general as far as the name of the variable resp. function is known. This can only be handled by leaving internal variables and functions strictly undocumented, which is not a proper solution after all. This is one of the greatest weak spots of the OOP implementation of PHP4 at all !


  2. Missing Destructor

  3. Like already mentioned in the chapter on the constructor, any destructor is missing in PHP. This makes an automated cleanup during removal of an object from the memory impossible. In most cases this circumstance is hardly noticeable in practice and can be handled with a normal function as well, whereby one has to rely on the discipline of the programmer who uses the function which is an insecure matter.


  4. No Multiple Inheritance

  5. It is possible in other languages to derive a class not only from one other class, but also from several classes at the same time. The new class inherits all properties of all ancestors. In PHP you can only derive from one class. Herewith PHP forfeits a certain flexibility compared with other languages, but on the other hand programmers are thereby forced to attend more to the concept of hierarchy in their work and to make better design. This makes complex libraries like the Portalsuite Objects more transparent for tiroes. The professional might miss another powerful tool for creating complex and logic object worlds.


  6. No Overloading

  7. Some languages like - for instance - C++ allow to use the same function name several times if the parameter lists differ enough. This multiple use is called overloading. Often this is very comfortable since one does not have to amend and - as a frequent consequence - to „disfigure“ significant function names with type names and parameters. Currently overloading is not possible in PHP. Naturally you can compensate for this in practice by case discriminations etc. Of course this may result in a more complex code.



    Currently it is discussed in public forums and mailing lists of the PHP community if and how these missing object-oriented properties shall be integrated into the PHP version 5. The company „Zend“, which developed PHP’s internal engine, provides a basis for discussion with the version 2 of the Zend PHP engine regarding the implementation. But currently it is uncertain what will be implemented and how.