|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53586 parent::__construct destroys object if exception is thrown
Submitted: 2010-12-21 10:03 UTC Modified: 2010-12-21 18:39 UTC
Avg. Score:4.2 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: peters at yandex dot ru Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.3.4 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: peters at yandex dot ru
New email:
PHP Version: OS:


 [2010-12-21 10:03 UTC] peters at yandex dot ru
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()
		catch (Exception $e)

new B('');

Expected result:
object(B)#45 (0) { } 

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-21 18:39 UTC]
-Status: Open +Status: Bogus
 [2010-12-21 18:39 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 18:01:30 2024 UTC