From: jb at ez dot no Operating system: Kubuntu 6.10 PHP version: 5.2.0 PHP Bug Type: *General Issues Bug description: Destructor is called allthought constructor is never called
Description: ------------ It is possible for PHP to call the __destruct() on an object allthough __construct() was never called. This seems to happen when having nested object creations and the inner one throws and exception in the constructor. The attached reproducable code shows the problem: Child::__construct() [Child] Master::__destruct() [Master] If the last line is changed to: $b = new Child(); $a = new Master( $b ); it works of course. In general destructors should never be called if the constructor was not called or even if it did not finish. Reproduce code: --------------- class Master { public function __construct( $child ) { echo __CLASS__, "::__construct() [", get_class( $this ), "]\n"; } public function __destruct() { echo __CLASS__, "::__destruct() [", get_class( $this ), "]\n"; } } class Child { public function __construct() { echo __CLASS__, "::__construct() [", get_class( $this ), "]\n"; throw new Exception( "Child failure" ); } public function __destruct() { echo __CLASS__, "::__destruct() [", get_class( $this ), "]\n"; } } $a = new Master( new Child() ); Expected result: ---------------- Child::__construct() [Child] Actual result: -------------- Child::__construct() [Child] Master::__destruct() [Master] -- Edit bug report at http://bugs.php.net/?id=39868&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39868&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39868&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39868&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39868&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39868&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39868&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39868&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39868&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39868&r=support Expected behavior: http://bugs.php.net/fix.php?id=39868&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39868&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39868&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39868&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39868&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39868&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39868&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39868&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39868&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39868&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39868&r=mysqlcfg