Reply to Reassigning variable to new object destroys old one?

Your name:

Reply:


Posted by woger151 on 04/30/07 14:35

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

[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

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