Re: destructor not called for static members?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Richard Lynch wrote:
>>><?php
>>>class c1 {
>>>   public function __destruct() {
>>>     echo '__destruct';
>>>   }
>>>}
>>>
>>>class c2 {
>>>   private static $_ref;
>>>
>>>   public function __construct() {
>>>     self::$_ref = new c1();
>>>
>>>     //$this->_ref =  new c1();
>>>   }
>>>}
>>>
>>>$obj = new c2();
>>>unset($obj);
>>>?>
>>>

> self::$_ref is completely independent of any instance of that class.

c2::$_ref has no value unless and until you create at least one (1) c2
instance.

That is the only dependency.

c2::$_ref cannot be destroyed by PHP unless and until the entire script is
dying because it is STATIC and if you create a second c2, it shouldn't
change, right?

So you only ever have, at most, one c1 running around.

You have no c1's until you create a c2.

Then you have 1 c1 until the script ends.

At least, that's what I'd expect from a STATIC property based on other OO
languages...  Never actually used PHP's OO stuff for reasons we needn't
repeat.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux