Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41314 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97370 invoked from network); 22 Oct 2008 07:31:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Oct 2008 07:31:40 -0000 X-Host-Fingerprint: 62.177.129.191 62-177-129-191.bbned.nl Received: from [62.177.129.191] ([62.177.129.191:15310] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/54-62149-BD6DEF84 for ; Wed, 22 Oct 2008 03:31:39 -0400 To: internals@lists.php.net,Alexey Zakhlestin Message-ID: <48FED6DA.2090400@naenius.com> Date: Wed, 22 Oct 2008 09:31:38 +0200 User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 CC: Ryan Panning , internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 62.177.129.191 Subject: Re: [PHP-DEV] Destructor Order From: mike.vanriel@naenius.com (Mike van Riel) Alexey Zakhlestin wrote: > On Wed, Oct 22, 2008 at 5:03 AM, Ryan Panning wrote: >> I've been wondering, is such a thing even possible? Is there a good way to >> implement an object destruct order? Here are my thoughts: >> >> In the class definition, specify what "level" of destruction the objects >> should be on. How, I have no idea, I haven't thought of a good syntax. It >> should be an integer for what level though. >> >> Then when the script ends, the engine starts with the highest most level of >> destruction. It continues down until everything has been destructed. With >> the last most level being objects with unspecified levels. >> >> Note: Each level can have more than one class. >> >> Example destruction order: >> 3 = database records (ActiveRecord or such) >> 2 = database connection object >> 1 = framework objects >> 0 = objects with unspecified level > > > Why would you need such thing? > PHP uses reference-counting and destroys objects as soon, as there are > no more references to them. Since PHP 5.3, it also detects > cyclic-references and periodically destroys object-groups which have > references to each other, but do not have references from external > context. > > Additionally, AFAIK in an ideal situation a destructor should only destroy objects which exist during the lifetime of an instance of the class containing the destructor. If objects have a greater lifespan (i.e. shared) then they should be destroyed by other means, like at the end of their lifespan or at the end of your script.