Edit report at https://bugs.php.net/bug.php?id=72656&edit=1
ID: 72656
Updated by: cmb@php.net
Reported by: joe88 dot ds at gmail dot com
Summary: Object destructor called before constructor
Status: Verified
-Type: Bug
+Type: Documentation Problem
Package: Scripting Engine problem
Operating System: Windows 7 x64
PHP Version: 5.5.38
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
No, this is not a bug. Actually, the behavior is mostly
documented[1]:
| Classes which have a constructor method call this method on each
| newly-created object, [â¦]
and[2]:
| The destructor will be called even if script execution is
| stopped using exit().
The only missing peace to the puzzle is eager evaluation of
function arguments, which doesn't appear to be documented yet.
[1] <https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor>
[2] <https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.destructor>
Previous Comments:
------------------------------------------------------------------------
[2016-07-25 09:48:04] cmb@php.net
There doesn't even need to be an error handler involved, see
<https://3v4l.org/cR3nF>. Looking at the opcodes[1] hints
at
what's going on behind the scenes: first NEW is executed, and only
after that the arguments for the constructor are evaluated, which,
in this case, cause the script to terminate, without actually
calling the constructor. On shutdown, however, the newly created
object gets properly destroyed by calling its destructor.
In my opinion, this is a bug.
[1] <https://3v4l.org/cR3nF/vld#tabs>
------------------------------------------------------------------------
[2016-07-23 05:29:10] joe88 dot ds at gmail dot com
Description:
------------
Calling exit from a user error handler causes an object to be destructed, even if
the object was never constructed.
Test script:
---------------
http://pastebin.com/UeBBj1hK
Expected result:
----------------
The Tree's destructor should never be called.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72656&edit=1