Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41316 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35332 invoked from network); 22 Oct 2008 09:21:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Oct 2008 09:21:34 -0000 Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fmethod.com from 69.16.228.148 cause and error) X-PHP-List-Original-Sender: sv_forums@fmethod.com X-Host-Fingerprint: 69.16.228.148 unknown Linux 2.4/2.6 Received: from [69.16.228.148] ([69.16.228.148:57285] helo=host.fmethod.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/EA-62149-C90FEF84 for ; Wed, 22 Oct 2008 05:21:33 -0400 Received: from [83.228.56.37] (port=2111 helo=pc) by host.fmethod.com with esmtpa (Exim 4.69) (envelope-from ) id 1KsZuD-0003JI-BP for internals@lists.php.net; Wed, 22 Oct 2008 04:21:29 -0500 Message-ID: <2B4E043EDD2C4659A56F0E3098F84913@pc> To: References: <48FED6DA.2090400@naenius.com> Date: Wed, 22 Oct 2008 12:21:24 +0300 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 x-mimeole: Produced By Microsoft MimeOLE V6.00.2900.5579 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host.fmethod.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - fmethod.com Subject: Re: [PHP-DEV] Destructor Order From: sv_forums@fmethod.com ("Stan Vassilev | FM") >> 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 >> Hi, This would likely (and possibly rightfully) be frowned upon, but according to the current codebase, if the destructor creates a new reference outside to the destroyed object while it runs, the object won't be garbage collected (a safe call is used that checks for any remaining references after the destructor is called). This allows you to implement destruction priorities yourself easily by using a central "DestructManager": function __destruct() { global $destructManager; $this->addObject($this, $priority); } function __real_destruct() { .... } Those will be collected in the destruction manager and when at shutdown, on the manager's own destructor you just need to sort the collection by priority and call the "real" destructor. Now, this will work fine, but has this downside that all objects will be held in the memory until script shutdown, so it's naturally not good for long running processes. Regards, Stan Vassilev