Bug #29368 [Csd]: The destructor is called when an exception is thrown from the constructor

From: Date: Wed, 13 Jul 2016 13:46:16 +0000
Subject: Bug #29368 [Csd]: The destructor is called when an exception is thrown from the constructor
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202281@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=29368&edit=1

 ID:                 29368
 Updated by:         dmitry@php.net
 Reported by:        fixxxer at php5 dot ru
 Summary:            The destructor is called when an exception is thrown
                     from the constructor
 Status:             Closed
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        5.4.0
 Assigned To:        helly
 Block user comment: N
 Private report:     N

 New Comment:

Fixed in PHP-7.1 only, because the fix causes minor BC break.
http://git.php.net/?p=php-src.git;a=commitdiff;h=afd3e39d6697e36d3b92cee5da911e4ea0de3901


Previous Comments:
------------------------------------------------------------------------
[2016-07-13 13:44:07] dmitry@php.net

Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=afd3e39d6697e36d3b92cee5da911e4ea0de3901
Log: Fixed bug #29368 (The destructor is called when an exception is thrown from the constructor).

------------------------------------------------------------------------
[2013-01-06 04:17:49] stas@php.net

Related To: Bug #45351

------------------------------------------------------------------------
[2013-01-06 04:14:29] stas@php.net

This bug is still reproducible in 5.4 with this code:

<?php

function throwme($arg)
{
    throw new Exception;
}

class foo {
  function __construct() {
    echo "Inside constructor\n";
    throwme($this);
  }

  function __destruct() {
    echo "Inside destructor\n";
  }
}

try {
  $bar = new foo;
} catch(Exception $exc) {
  echo "Caught exception!\n";
}

This produces:
Inside constructor
Caught exception!
Inside destructor

This is because the object is kept as part of "args" in the exception's 
backtrace. Better solution is needed here, the one in 
f5cf052225ff4bc5ba7fe2c8b9f0ffcd980cac6f does not solve the whole issue.

------------------------------------------------------------------------
[2004-09-24 16:43:45] ernest at vogelsinger dot at

This bug still (again?) exists in 5.0.2/Win32!

------------------------------------------------------------------------
[2004-07-25 19:39:06] helly@php.net

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.



------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=29368


--
Edit this bug report at https://bugs.php.net/bug.php?id=29368&edit=1


Thread (7 messages)

« previous php.bugs (#202281) next »