Re: Destructor Order

From: Date: Thu, 23 Oct 2008 11:22:45 +0000
Subject: Re: Destructor Order
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-41341@lists.php.net to get a copy of this message
Diogo Galvão wrote:
"The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence." As far as I understand it if your active record references the PDO instance (say $this->conn) your object gets destroyed before the connection object. Perhaps it's a better approach then introducing destruction order for global or singleton problems. wbr, Diogo Larry Garfield wrote:
On Wednesday 22 October 2008 2:31:38 am Mike van Riel wrote: 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.
just to add it in; in ejb3 in java you have PostConstruct and PreDestroy which are pretty useful; maybe something along the same lines could be implemented in PHP? regards! -- nathan ( nathan@kraya.co.uk ) { Senior Web Developer php + java + flex + xmpp + xml + ecmascript web development edinburgh | http://kraya.co.uk/ }

« previous php.internals (#41341) next »