Reply to Re: Global references to objects

Your name:

Reply:


Posted by Oli Filth on 12/29/05 16:30

Lüpher Cypher said the following on 29/12/2005 14:07:
> Hi,
>
> Suppose I instantiate an object $a and store it in a global array. Now,
> if I change a property of $a, the property in $a will have the new
> value, but the property in the global array will have the old one. Does
> anyone know workarounds?
>
<...SNIP CODE...>
>
> Is there a way to store an object by reference so that whenever its
> properties change, the global array item would still be referring the
> actual object and not a copy of it I assume it made on the assigment?

I'm assuming you must be using PHP 4, because this works as you want it
to in PHP 5.

In PHP 4, objects are copied by value; in PHP 5, objects are copied by
reference.

To copy by reference in PHP 4, use &, i.e.:

$global[0] =& $a;



(P.S. This is nothing to do with global variables...)

--
Oli

[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

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