Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41372 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59999 invoked from network); 24 Oct 2008 18:39:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Oct 2008 18:39:52 -0000 X-Host-Fingerprint: 64.8.134.189 unknown Received: from [64.8.134.189] ([64.8.134.189:21216] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/C4-01351-77612094 for ; Fri, 24 Oct 2008 14:39:51 -0400 Message-ID: To: internals@lists.php.net Date: Fri, 24 Oct 2008 13:39:44 -0500 User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 64.8.134.189 Subject: Re: Destructor Order From: rpanning@gmail.com (Ryan Panning) 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 Hi, I've been out sick the past couple days so I haven't been able to keep on eye on this. Thanks for all the feedback, all good points. As for the comments about bad practice: I understand that it's not the best thing to rely on. But, when you have objects relying on other objects to do things (may not have a reference to them), it's hard to use the __destruct() method. In which case makes __destruct() not all that useful. As for comments about different approaches: Making my own shutdown process is what I and I'm assuming everyone else has been doing. However, I'm just thinking that if there was a built-in way of doing this that it would be easier to make cross-application plugin types of things. Marcus: Interesting, I didn't know you had tried this already. Good to know that you've tested it. Pre-destruction method: I like the idea about a pre-destruction method. It would give the user a chance to do something before other objects are destroyed. Is this something that would slow down PHP too much?