Title: Delegation (a/k/a. Object-Based Inheritance) Version: $Revision$ Status: draft Maintainer: Sebastian Bergmann Dynamic Delegation Syntax / Example delegatee = $delegatee; } } $foo = new Foo; $foo->setDelegatee(new aDelegatee); $foo->doSomething(); /* prints "hubu" */ $foo->setDelegatee(new anotherDelegatee); $foo->doSomething(); /* prints "tubu" */ ?> Semantics / Synopsis The "Foo" class may use all methods available in "$bar" as if they where locally defined or inherited from a superclass. The essential difference is that by assigning another object to "$bar" it is possible to dynamically switch between different implementations for these methods. Fixed Delegation Syntax / Example doSomething(); /* prints "hubu" */ ?> Semantics / Synopsis The "Foo" class may use all methods available in "$bar" as if they where locally defined or inherited from a superclass. The difference to the dynamic delegation is that once the delegatee object is set, it cannot be changed. Default Delegation Syntax / Example bar(); /* prints "bar" */ ?> Semantics / Synopsis If a class has a __delegate() method, it is called whenever a method on an object of this class is called that is * Not defined in the class. * Not provided by a delegatee object. The __delegate() method is called with the name and parameters of the method call. This supersedes / obsoletes similar functionality introduced in Zend Engine 1 by ext/overload.