#42617 [Opn->Ver]: Destructor not getting called when reference is overwritten
| From: | jani@php.net | Date: | Mon, 22 Oct 2007 11:22:06 +0000 |
| Subject: | #42617 [Opn->Ver]: Destructor not getting called when reference is overwritten | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-118822@lists.php.net to get a copy of this message | ||
ID: 42617
Updated by: jani@php.net
Reported By: garethinwales at gmail dot com
-Status: Open
+Status: Verified
Bug Type: Scripting Engine problem
Operating System: CentOS 5
-PHP Version: 5.2.4
+PHP Version: 5.3CVS-2007-10-22
New Comment:
Simplified code:
<?php
class one {
function __construct() {
echo "__construct()\n";
}
function __destruct() {
echo "__destruct()\n";
}
}
$a = new one;
// $a = null;
$a = new one;
?>
Outputs:
__construct()
__construct()
__destruct()
__destruct()
And when the $a = null; line is uncommented:
__construct()
__destruct()
__construct()
__destruct()
Previous Comments:
------------------------------------------------------------------------
[2007-09-10 19:22:17] garethinwales at gmail dot com
Description:
------------
When the class member $one of class two is replaced by a new object
instance, the destructor is not called.
This seems incorrect as the previous object is being remove with no
references and therefore the destructor should be called.
you can get what I'd assume to be the currect fucntionality by
uncommenting the line // $this->one=null;
Many thanks
Gareth Jones
Reproduce code:
---------------
class one {
function __construct() {
echo "__construct() one\n";
}
function __destruct() {
echo "__destruct() one\n";
}
}
class two {
public $one = null;
function __construct() {
echo "__construct() two\n";
$this->one = new one();
// $this->one=null;
$this->one = new one();
}
function __destruct() {
echo "__destruct() two\n";
}
}
$two = new two();
Expected result:
----------------
__construct() two
__construct() one
__destruct() one
__construct() one
__destruct() two
__destruct() one
Actual result:
--------------
__construct() two
__construct() one
__construct() one
__destruct() one
__destruct() two
__destruct() one
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42617&edit=1