Re: unset( $anobject) does not invoce __destruct()
am 24.08.2009 14:46:44 von kranthi
unset($obj) always calls the __destruct() function of the class.
in your case clearly you are missing something else. Probably
unset($anobject) is not being called at all ?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: unset( $anobject) does not invoce __destruct()
am 24.08.2009 15:10:17 von Lupus Michaelis
kranthi wrote:
> unset($obj) always calls the __destruct() function of the class.
Never calls the dtor. The dtor will be called only when the reference
count reaches 0.
class c { function __destruct() { echo 'dying !' ; } }
$v1 = new c ;
$v2 = $v1 ;
unset($v1) ; // don't call the dtor
unset($v2) ; // call the dtor
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: unset( $anobject) does not invoce __destruct()
am 24.08.2009 15:46:22 von Ralph Deffke
this is also not the full truth try this and it works
what are the circumstances that is causing this problem then, yes I do have
distributed references over my script and there are clearly references still
set, however after running the snipped script I can not see what I do
special in my script causing the problem. I even tried with public and
private static in other objects. it works. however the manual indicates the
refernce counter has to be 0.
abstract class a {
public function __construct(){
echo "constructing....
";
}
public function __destruct(){
echo "destructing....
";
}
}
class b extends a{
}
$c = new b();
$d = $c ; // works
$f[] = $c ; // works
class e {
private $m;
public function setM( $m ){
$this->m = $m;
}
}
$o = new e();
$o->setM( $c ); // works
unset( $c );
?>
"Lupus Michaelis" wrote in message
news:41.F9.03363.011929A4@pb1.pair.com...
> kranthi wrote:
> > unset($obj) always calls the __destruct() function of the class.
>
> Never calls the dtor. The dtor will be called only when the reference
> count reaches 0.
>
> class c { function __destruct() { echo 'dying !' ; } }
> $v1 = new c ;
> $v2 = $v1 ;
>
> unset($v1) ; // don't call the dtor
> unset($v2) ; // call the dtor
>
> --
> Mickaël Wolff aka Lupus Michaelis
> http://lupusmic.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php