|
Posted by Janwillem Borleffs on 09/24/06 14:32
Wenting, Marcel wrote:
> Has anyone a clue how to achieve this?
> parent doesnt work since it is no inheritance.
>
The easiest way to accomplish this, is to store references. The following
example, tailored for PHP4, provides an example:
class A { function myname() { print 'A'; }}
class B { function myname() { print 'B'; }}
class C {
var $objects;
function C(&$obj) { $this->objects[] =& $obj ; }
function myname() { print $this->objects[0]->myname(); }
}
$d = new stdClass; # container
$d->a = new A;
$d->a->b = new B;
$d->a->b->c = new C($d->a->b);
$d->a->b->c->myname(); # prints B
HTH;
JW
Navigation:
[Reply to this message]
|