Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41329 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74930 invoked from network); 23 Oct 2008 02:24:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Oct 2008 02:24:03 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.30.48 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.30.48 qmta05.emeryville.ca.mail.comcast.net Received: from [76.96.30.48] ([76.96.30.48:50925] helo=QMTA05.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8E/BE-41302-240EFF84 for ; Wed, 22 Oct 2008 22:24:02 -0400 Received: from OMTA04.emeryville.ca.mail.comcast.net ([76.96.30.35]) by QMTA05.emeryville.ca.mail.comcast.net with comcast id VmdD1a00E0lTkoCA52PzWF; Thu, 23 Oct 2008 02:23:59 +0000 Received: from earth.ufp ([24.13.255.226]) by OMTA04.emeryville.ca.mail.comcast.net with comcast id W2Py1a01E4trKQ88Q2Pzpb; Thu, 23 Oct 2008 02:23:59 +0000 X-Authority-Analysis: v=1.0 c=1 a=aJTWpn6OZfuHygz-TAAA:9 a=lRlsOVK1b8aDAdZ5hT0A:7 a=BnWCutUqpny-Ke5uH3aaMqehgiMA:4 a=FHBbIDN7CdwA:10 a=LY0hPdMaydYA:10 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 9CA03D7A33 for ; Wed, 22 Oct 2008 21:23:58 -0500 (CDT) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vRlFg7hKOtad for ; Wed, 22 Oct 2008 21:23:58 -0500 (CDT) Received: from luna (unknown [192.168.42.1]) by earth.ufp (Postfix) with ESMTPSA id 7ECC1D7A10 for ; Wed, 22 Oct 2008 21:23:58 -0500 (CDT) To: internals@lists.php.net Date: Wed, 22 Oct 2008 21:23:58 -0500 User-Agent: KMail/1.9.10 References: <48FED6DA.2090400@naenius.com> In-Reply-To: <48FED6DA.2090400@naenius.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200810222123.58206.larry@garfieldtech.com> Subject: Re: [PHP-DEV] Destructor Order From: larry@garfieldtech.com (Larry Garfield) On Wednesday 22 October 2008 2:31:38 am Mike van Riel wrote: > >> 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. I believe the "end of your script" part is the problem. Imagine you have some object (say, ActiveRecord style) that writes itself to the database when it's destroyed if the data has been modified. Now cache that object in a static variable somewhere for performance. You're also using PDO, so your database connection is a global or singleton instance of the PDO class. Then your script reaches the end. Does your object get destroyed and therefore saved to the database before or after the PDO object goes away? I don't actually know. I'm not saying that manual destructor order is the correct way to deal with that issue necessarily, but I think that's the sort of use case it's intended to address. -- Larry Garfield larry@garfieldtech.com