From:             fixxxer at php5 dot ru
Operating system: Any
PHP version:      5CVS-2004-07-24 (dev)
PHP Bug Type:     Zend Engine 2 problem
Bug description:  The destructor is called when an exception is thrown from the 
constructor

Description:
------------
The destructor is called if throwing an exception from the constructor.
This seems at least illogical and it's contrary to usual behaviour of
alike languages like C++ where destructor is not called in this case.

Reproduce code:
---------------
<?

class foo {
  function __construct() {
    echo "Inside constructor\n";
    throw new Exception;
  }
  function __destruct() {
    echo "Inside destructor\n";
  }
}

try {
  $bar = new foo;
} catch(Exception $exc) {
  echo "Caught exception!\n";
}

?>

Expected result:
----------------
Inside constructor
Caught exception!

Actual result:
--------------
Inside constructor
Inside destructor
Caught exception!

-- 
Edit bug report at http://bugs.php.net/?id=29368&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29368&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29368&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=29368&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=29368&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=29368&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=29368&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=29368&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=29368&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=29368&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=29368&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=29368&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=29368&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29368&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=29368&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=29368&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=29368&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29368&r=float

Reply via email to