php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77882 Different behavior: always calls destructor
Submitted: 2019-04-12 09:35 UTC Modified: 2019-04-15 08:16 UTC
From: qRoC dot Work at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: Irrelevant OS: All
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: qRoC dot Work at gmail dot com
New email:
PHP Version: OS:

 

 [2019-04-12 09:35 UTC] qRoC dot Work at gmail dot com
Description:
------------
If we throw exception from constructor and create object by "new" - destructor never called.

But if we create object by ReflectionClass - destructor always by called.

Test script:
---------------
<?php
class Test {
    public function __construct() {
        throw new Exception();
    }
    
    public function __destruct() {
        echo '__destruct';
    }
}

try {
    new Test();
} catch(Exception $e) {
    
}
echo '--';
try {
    $ref = new ReflectionClass('Test');
    $obj = $ref->newInstance();
} catch(Exception $e) {
    
}


Expected result:
----------------
--

Actual result:
--------------
--__destruct

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-15 08:16 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2019-04-15 08:24 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e9c0367fdc4653331f398df36a10db1c54d6f3df
Log: Fixed bug #77882
 [2019-04-15 08:24 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2019-04-15 08:25 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e9c0367fdc4653331f398df36a10db1c54d6f3df
Log: Fixed bug #77882
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Mar 31 06:01:30 2025 UTC