Multiple Inheritance in PHP - a workaround
It is well known that PHP doesn't offer multiple inheritance, instead it provides interfaces. Altough the interfaces are something very good they can not fully replace the multiple inheritance. Of course some people voice opinions that if you need multiple inheritance then the design of the application is wrong - this will not be covered here. Instead we will investigate what are the...
Tags: How to... PHP 5.3 PHP General Tips and Tricks
Continue reading...New objects and value assignment
In PHP 4 was possible the constructor to return a value (different from the object). Here is a simple example how this would work in PHP 4: Of course this does not work in PHP 5.3 - first it will throw an error on the $this assignment, second - in PHP 5.3 the new operator always returns an object. In PHP 5 the constructor can be interrupted by throwing an exception and this will prevent the...
Tags: PHP General Tips and Tricks
Continue reading...Mirror, mirror, on the wall… what is this Reflection for?
In PHP 5.0 the Reflection extension was introduced. It is not kind of the usual extensions for manipulating or retreiving some sort of data, it is not adding support for a new protocol, it is something much more different and much more important (which is reflected in its documentation being placed under “Variables and Type Related Extensions“). This extension gives the possibility php code to...
Tags: How to... PHP General
Continue reading...Scope propagation bug in call_user_func()
In the previous entry about the scope propagation when call_user_func() is used for static calls few examples were given. They all work correctly in php 5.3 (while some don’t in php 5.2 and this was the BC change). But we have found a case when the scope is not propagated even in PHP 5.3: This yields the incorrect result of: A $this is not defined $this is not defined This means that the scope...
Continue reading...Scope propagation in static methods and call_user_func()
The entry in the backward incompatible changes says: The call_user_func() family of functions now propagate $this even if the callee is a parent class. Lets first give some examples for PHP 5.2… starting with an ordinary static call: This example contains two odd things – the first is that a dynamic method is called statically and no errors are produced at all and the second is that $this is...
Continue reading...