Edit report at http://bugs.php.net/bug.php?id=53586&edit=1
ID: 53586 Updated by: [email protected] Reported by: peters at yandex dot ru Summary: parent::__construct destroys object if exception is thrown -Status: Open +Status: Bogus Type: Bug Package: PDO related Operating System: Linux PHP Version: 5.3.4 Block user comment: N Private report: N New Comment: This is a proper, safe way to handle the exception. The exception in a constructor means the object is likely not in a valid state after it. PHP itself doesn't require parent constructors to be called and, if they're called and there's an exception, it allows catching the exception. In my opinion this a bad choice, but for internal objects it's much worse because the consequences of an internal object in an invalid state are segfaults and other problems. Closing as bogus. Previous Comments: ------------------------------------------------------------------------ [2010-12-21 10:03:55] peters at yandex dot ru Description: ------------ When calling parent::__construct() in any(!) method of PDO successor class and exception is thrown in parent::__construct() successor object is destroyed regardless of the fact that exception is properly caught. Test script: --------------- class B extends PDO { public function __construct() { try { parent::__construct(''); } catch (Exception $e) { } var_dump($this); } } new B(''); Expected result: ---------------- object(B)#45 (0) { } Actual result: -------------- NULL ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53586&edit=1
