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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Fri Sep 20 11:01:26 2019 UTC