2008/10/22 Ryan Panning <[EMAIL PROTECTED]>: > 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!" -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php