You are here: Re: __destruct() destroy an object that contains a reference to another object « PHP Programming Language « IT news, forums, messages
Re: __destruct() destroy an object that contains a reference to another object

Posted by Rik on 07/19/07 11:57

On Thu, 19 Jul 2007 14:54:26 +0200, Jerry Stuckle
<jstucklex@attglobal.net> wrote:

> Mortimer wrote:
>> Hi, i'm using PHP 5.1
>> I have two objects and the second one is using an instance of the
>> first.
>> As displayed in the example below, the Garbage Collector calls the
>> destruct method of the first class before the second even if the second
>> contains a reference to the other, so i can't complete all the
>> operations not having all "the code available"!
>> Thank you
>> Ex.:
>> class MyFirstClass
>> {
>> public function __construct()
>> {
>> ... operations...
>> }
>> public function __destruct()
>> {
>> echo "Destroyed MyFirstClass";
>> }
>> }
>> class MySecondClass
>> {
>> private $obj = NULL
>> public function __construct($obj)
>> {
>> ... operations...
>> }
>> public function __destruct()
>> {
>> echo "Destroyed MySecondClass";
>> }
>> }
>> $obj1 = new MyFirstClass();
>> $obj2 = new MySecondClass($obj1);
>> // Result
>> // Destroyed MyFirstClass
>> // Destroyed MySecondClass
>>
>
> Hmmm, personally I would consider this to be a bug. I'd suggest you
> report it and see what they say.
>
> Iván has a valid point when it comes to circular references, but that's
> not the case here. I think PHP should be able to determine which object
> should be destroyed first.
>

Then again, if there is a specific order to be followed, why not
explicitly set in in a register_shutdown_function()? It would be the short
solution, allbeit not that OO-pleasing.

--
Rik Wasmus

 

Navigation:

[Reply to this 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

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