note 117547 added to language.oop5.decon
| From: | 479258741 at qq dot com | Date: | Fri, 26 Jun 2015 10:54:10 +0000 |
| Subject: | note 117547 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202965@lists.php.net to get a copy of this message | ||
If a new reference of the object is created during __destruct, the memory for the object will not be
freed, and the __destruct will not be called for a second time.
<?php
class Foo{
public $i = "I=12345678\n";
public function showI(){
echo($this->i);
}
public function __destruct(){
echo("in __destruct\n");
if($GLOBALS['flag'])
$GLOBALS['test'][0] = $this;
}
}
$flag = true;
$test = [new Foo()];
echo("deleting Foo\n");
unset($test[0]);
echo("deleted Foo\n");
$test[0]->showI();
$flag = false;
echo("re-deleting Foo\n");
unset($test[0]);
echo("deleted Foo\n");
?>
In the above example, the output is:
deleting Foo
in __destruct
deleted Foo
I=12345678
re-deleting Foo
deleted Foo
so the __destruct was called only once and the memory was not freed.
----
Server IP: 72.52.91.14
Probable Submitter: 58.34.58.210
----
Manual Page -- http://php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/117547
Del: integrated -- https://master.php.net/note/delete/117547/integrated
Del: useless -- https://master.php.net/note/delete/117547/useless
Del: bad code -- https://master.php.net/note/delete/117547/bad+code
Del: spam -- https://master.php.net/note/delete/117547/spam
Del: non-english -- https://master.php.net/note/delete/117547/non-english
Del: in docs -- https://master.php.net/note/delete/117547/in+docs
Del: other reasons-- https://master.php.net/note/delete/117547
Reject -- https://master.php.net/note/reject/117547
Search -- https://master.php.net/manage/user-notes.php