note 81116 added to language.oop5.decon

From: Date: Thu, 14 Feb 2008 18:53:08 +0000
Subject: note 81116 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-136149@lists.php.net to get a copy of this message
Function __destruct is not executed by a call unset for a class. <?php class A{ public $parent_class; public function add_parent(&$class){ echo "Add parent class\n"; $this->parent_class = &$class; } public function __construct(){ echo "Construct Class A\n"; } public function __destruct(){ echo "Desctruct class A\n"; } } class B{ public $one_class; public function test(){ $this->one_class = new A; $this->one_class->add_parent(&$this); } public function __construct(){ echo "Construct Class B\n"; } public function __destruct(){ echo "Desctruct class B\n"; } } echo "init class B\n"; $test_cl = new B(); echo "run test func\n"; $test_cl->test(); echo "try unset B\n"; unset($test_cl); echo "now this class='".var_export($test_cl, true)."' \n"; echo "end script\n"; ?> Show -------------------- init class B Construct Class B run test func Construct Class A Add parent class try unset B now this class='NULL' end script Desctruct class B Desctruct class A -------------------- The lost class to which there is no access turns out? php -v PHP 5.2.1 (cli) (built: Nov 28 2007 23:14:55) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies ---- Server IP: 91.196.196.241 Probable Submitter: 91.124.211.100 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- https://master.php.net/note/edit/81116 Del: integrated -- https://master.php.net/note/delete/81116/integrated Del: useless -- https://master.php.net/note/delete/81116/useless Del: bad code -- https://master.php.net/note/delete/81116/bad+code Del: spam -- https://master.php.net/note/delete/81116/spam Del: non-english -- https://master.php.net/note/delete/81116/non-english Del: in docs -- https://master.php.net/note/delete/81116/in+docs Del: other reasons-- https://master.php.net/note/delete/81116 Reject -- https://master.php.net/note/reject/81116 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136149) next »