note 48532 added to language.oop5.decon

From: Date: Tue, 28 Dec 2004 18:50:42 +0000
Subject: note 48532 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-82413@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48532 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48532&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48532&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48532&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48532&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48532&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48532&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48532&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82413) next »