note 48532 deleted from language.oop5.decon by tularis
| From: | tularis@php.net | Date: | Tue, 28 Dec 2004 20:09:31 +0000 |
| Subject: | note 48532 deleted from language.oop5.decon by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-82415@lists.php.net to get a copy of this message | ||
Note Submitter: sir dot gallahad at gmail dot com
----
The PHP engine will clean all objects that haven't been destroyed at the and of the page
script. In order to explictly destroy an object you must set it to NULL. Here is an example:
<?
class A {
public $aVar;
function __construct( $pMe ) {
$this->aVar = $pMe;
echo "constructor of ".$this->aVar." called<br>";
}
function __destruct() {
echo "destructor of ".$this->aVar." called<br>";
}
}
$v1 = new A("v1");
$v1 = null; // this object will be destroyed here
echo "some other text here<br>";
$v2 = new A("v2");
?>
The result of this script will be:
constructor of v1 called
destructor of v1 called
some other text here
constructor of v2 called
destructor of v2 called
If you supress the line with "$v1 = null;" the result will be:
constructor of v1 called
some other text here
constructor of v2 called
destructor of v1 called
destructor of v2 called
Notice that at the end of the script the classes will be destroyed in the same order they were
created, i.e. first created first destroyed.
----
Reason: useless example