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, I've been out sick the past couple days so I haven't been able to
keep on eye on this. Thanks for all the feedback, all good points.
As for the comments about bad practice: I understand that it's not the
best thing to rely on. But, when you have objects relying on other
objects to do things (may not have a reference to them), it's hard to
use the __destruct() method. In which case makes __destruct() not all
that useful.
As for comments about different approaches: Making my own shutdown
process is what I and I'm assuming everyone else has been doing.
However, I'm just thinking that if there was a built-in way of doing
this that it would be easier to make cross-application plugin types of
things.
Marcus: Interesting, I didn't know you had tried this already. Good to
know that you've tested it.
Pre-destruction method: I like the idea about a pre-destruction method.
It would give the user a chance to do something before other objects are
destroyed. Is this something that would slow down PHP too much?
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php