You are here: Re: Object Tree « All PHP « IT news, forums, messages
Re: Object Tree

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация