recently I came over a piece of code where this question arose.
scenarion: a new object is created locally in a class's method, but when will this object be destroyed? (ok, at latest at script end....)
[PHP]class myclass
{
function mymethod() {
$var = new AnotherClass;
// more code, $var will not be manually (unset()) destroyed
}
}
// now we use myclass to do something
$globalvar = new myclass;
$globalvar->mymethod();
unset($globalva r);
//more code
[/PHP]
what happens with (AnotherClass) $var? will it be destroyed when the method (mymethod()) is finished or when the container class (myclass) is destroyed? anyone an idea?
thanks
scenarion: a new object is created locally in a class's method, but when will this object be destroyed? (ok, at latest at script end....)
[PHP]class myclass
{
function mymethod() {
$var = new AnotherClass;
// more code, $var will not be manually (unset()) destroyed
}
}
// now we use myclass to do something
$globalvar = new myclass;
$globalvar->mymethod();
unset($globalva r);
//more code
[/PHP]
what happens with (AnotherClass) $var? will it be destroyed when the method (mymethod()) is finished or when the container class (myclass) is destroyed? anyone an idea?
thanks
Comment