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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC