Reply to Re: Reference to THIS from inside constructor

Your name:

Reply:


Posted by Tom on 02/01/07 17:32

On Feb 1, 9:55 am, "Tamagafk" <tamag...@gmail.com> wrote:
> Hi there,
> I heard storing reference to THIS from inside object's constructor can
> cause problems:
>
> $myObjects = array();
> class MyClass{
> function MyClass(){
> global $myObjects;
> $myObjects[] = $this;
> }
>
> }
>
> Do you know anything about that? It looks like when constructor
> finishes all such references lead to COPY of the object.

If you actually want to reference instead of copy, you need to do:
$myObjects[] = &$this ;

You can also do this outside the constructor when defining your
instance, e.g.:
$myObjects[] = &$ref ;
$ref = new MyClass() ;

[Back to original 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

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