ID:               42617
 Updated by:       [EMAIL PROTECTED]
 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

Reply via email to