|
Posted by Wenting, Marcel on 09/24/06 14:55
Janwillem Borleffs wrote:
Janwillem Borleffs wrote:
> 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
>
>
>
> 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
>
>
>
Jan Willem,
Perfect, how stupid that I didnt think of this.
Now I also remember C pointers again :)
Thanks a lot,
Marcel
Navigation:
[Reply to this message]
|