Reply to Re: Reassigning variable to new object destroys old one?

Your name:

Reply:


Posted by ZeldorBlat on 04/30/07 14:43

On Apr 30, 10:35 am, woger...@jqpx37.cotse.net wrote:
> If I write
> $x = new some_class($init_data1);
> and then
> $x = new some_class($init_data2);
>
> does the first object (constructed with $init_data1) get destroyed, or
> do I have to call unset() for that? And am I guaranteed that after
> the second call the value of $x will be as if the first call was never
> made?
>
> I tried using var_dump within a for loop to see what was happening
> (ie, using "new" and assigning it to the same variable name everyt
> ime), and in the printout I get stuff like
> object(some_class)#1
> alternating with
> object(some_class)#2
>
> If I call unset(), I don't get the #2. I'm assuming that (in the case
> I don't call unset()) PHP is destroying the variable every other
> iteration due to some kind of garbage collection algorithm. And the
> "#1" and "#2" refer to the actual object being referenced.
>
> TIA

The object is automatically destroyed when nothing is referencing it.
When you assign the second instance to $x, there is nothing left
referencing the first instance.

There was another thread on this subject recently:
<http://groups.google.com/group/comp.lang.php/browse_frm/thread/
7046181c4c507263/3e766edeeebbd5f5#3e766edeeebbd5f5>

[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

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