From:             garethinwales at gmail dot com
Operating system: CentOS 5
PHP version:      5.2.4
PHP Bug Type:     Scripting Engine problem
Bug description:  Destructor not getting called when reference is overwritten

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 bug report at http://bugs.php.net/?id=42617&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42617&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42617&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42617&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42617&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42617&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42617&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42617&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42617&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42617&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42617&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42617&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42617&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42617&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42617&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42617&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42617&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42617&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42617&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42617&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42617&r=mysqlcfg

Reply via email to