This is sometimes just for the purity of the meme. But in your exmaple $observer and ->$db_build reference sub-objects. Thus, the goal is to destroy them before destroying the current object. (Although I'm not sure that the Zend core really likes to be interrupted when it is in a destructive rage. Maybe it has a spool list or something like that.)
In any case, this is not necessary from the point of view of the GC. But it would be reasonable if there was some dependence in the composite subprojects; e.g. counters or registers. Therefore, in most cases, it was not necessary to speak.
I made a stupid example to demonstrate the __destruct order:
class dest { function __construct($name, $sub=NULL) { $this->name = $name; $this->sub = $sub; } function __destruct() { print "<destroying $this->name>\n"; $this->sub = NULL; print "</destroying $this->name>\n"; } } $d = new dest("first", new dest("second", new dest("third"))); exit;
Without $this->sub = NULL , objects will be destroyed individually, not necessarily in the order they were created. With the removal of compound objects manually, however, PHP destroys three objects in a nested module:
<destroying first> <destroying second> <destroying third> </destroying third> </destroying second> </destroying first>
mario source share