Reply to Re: [PHP] destructor not called for static members?

Your name:

Reply:


Posted by Richard Lynch on 10/16/46 11:10

> 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

[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

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