Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41345 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29314 invoked from network); 23 Oct 2008 13:36:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Oct 2008 13:36:23 -0000 Authentication-Results: pb1.pair.com header.from=rquadling@googlemail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=rquadling@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.217.14 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@googlemail.com X-Host-Fingerprint: 209.85.217.14 mail-gx0-f14.google.com Received: from [209.85.217.14] ([209.85.217.14:33799] helo=mail-gx0-f14.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/21-44135-5DD70094 for ; Thu, 23 Oct 2008 09:36:22 -0400 Received: by gxk7 with SMTP id 7so1301610gxk.23 for ; Thu, 23 Oct 2008 06:36:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=8NLrfIQCru0nw03j58kW5on96RbYz3p8exr0gmtl+7A=; b=yAhRZs60pBpE/xNcfJ5D5TYa9EUctG3pw8vEccUvOBAz+ea3IrSMxNBLHx86urAlLL Sxy0GgbICHSrTUDNP6Yzxm6fAfy0/q0flvrY5vYbrTSnv+44NXJt/vI6Hii4v5D/X8Cm 3S39RsH+gma9ZK+sJVD9nx8PM5pew3ijQFJ5A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:cc:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:references; b=fQDH/8y8Gd3t80fWyZIHjjOSXAaC5JhMp4dHLFuz6ceaNOfae5oemR8SwEnrgmHQtU 1NRjTmSCNf3/dgV3tTrr7h8tDn4fV+lgzk7abjiOe1AREzfDtuWZoJoBEMDPZAS6Dj8Z pviqIXM8fPiKryQCDUqCQD74j1JN0xJE0wR1U= Received: by 10.103.229.19 with SMTP id g19mr330872mur.19.1224768976795; Thu, 23 Oct 2008 06:36:16 -0700 (PDT) Received: by 10.103.212.17 with HTTP; Thu, 23 Oct 2008 06:36:16 -0700 (PDT) Message-ID: <10845a340810230636g7c2497beq2aa30ba8b1de67ae@mail.gmail.com> Date: Thu, 23 Oct 2008 14:36:16 +0100 Reply-To: RQuadling@GoogleMail.com To: "Ryan Panning" Cc: internals@lists.php.net In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: Subject: Re: [PHP-DEV] Destructor Order From: rquadling@googlemail.com ("Richard Quadling") 2008/10/22 Ryan Panning : > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > I solved my issues by adding the concept of "owner" to my base object class. So any instance not "owned", I'm saying I don't care about destruction order. For all "owned" instances, it is my responsibility to call the destructor of the root(s) of the owned instances. Having an array of references of the parent/child relationship (every parent knows its children and every child knows its parent) you can destroy all the children in FILO order before destroying self. It seems that you can't REALLY destroy an instance inside the destructor so I needed to "tag" instances as dead. That combined with a few methods to deal with adding a "child" and notifying of the change of ownership ($_obj_Owner is private) this works for me. I think having the base object supporting this concept would go a long way to allowing the developer decide when they had finished with things. Of course, this is probably more suited to long running apps rather than web scripts, true. I used to program using Delphi, and that is where I took this idea. I'm sure other languages have this. All my script start with a base class_App which is nothing more than a container for other instances and is a catch all for any unowned instance. All instances are destroyed specifically in reverse order - FILO - First In Last Out. Fortunately, I've not needed out of order destruction yet. Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"