note 76710 added to language.oop5.decon
| From: | prieler at abm dot at | Date: | Fri, 27 Jul 2007 07:42:56 +0000 |
| Subject: | note 76710 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128961@lists.php.net to get a copy of this message | ||
i have written a quick example about the order of destructors and shutdown functions in php 5.2.1:
<?php
class destruction {
var $name;
function destruction($name) {
$this->name = $name;
register_shutdown_function(array(&$this, "shutdown"));
}
function shutdown() {
echo 'shutdown: '.$this->name."\n";
}
function __destruct() {
echo 'destruct: '.$this->name."\n";
}
}
$a = new destruction('a: global 1');
function test() {
$b = new destruction('b: func 1');
$c = new destruction('c: func 2');
}
test();
$d = new destruction('d: global 2');
?>
this will output:
shutdown: a: global 1
shutdown: b: func 1
shutdown: c: func 2
shutdown: d: global 2
destruct: b: func 1
destruct: c: func 2
destruct: d: global 2
destruct: a: global 1
conclusions:
destructors are always called on script end.
destructors are called in order of their "context": first functions, then global objects
objects in function context are deleted in order as they are set (older objects first).
objects in global context are deleted in reverse order (older objects last)
shutdown functions are called before the destructors.
shutdown functions are called in there "register" order. ;)
regards, J
----
Server IP: 212.24.129.51
Probable Submitter: 193.84.94.131
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/76710
Del: integrated -- https://master.php.net/note/delete/76710/integrated
Del: useless -- https://master.php.net/note/delete/76710/useless
Del: bad code -- https://master.php.net/note/delete/76710/bad+code
Del: spam -- https://master.php.net/note/delete/76710/spam
Del: non-english -- https://master.php.net/note/delete/76710/non-english
Del: in docs -- https://master.php.net/note/delete/76710/in+docs
Del: other reasons-- https://master.php.net/note/delete/76710
Reject -- https://master.php.net/note/reject/76710
Search -- https://master.php.net/manage/user-notes.php