Doc #72656 [Ver->Csd]: Object destructor called before constructor
| From: | git@php.net | Date: | Fri, 27 Aug 2021 11:12:25 +0000 |
| Subject: | Doc #72656 [Ver->Csd]: Object destructor called before constructor | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-19123@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72656&edit=1
ID: 72656
Updated by: git@php.net
Reported by: joe88 dot ds at gmail dot com
Summary: Object destructor called before constructor
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: Scripting Engine problem
Operating System: Windows 7 x64
PHP Version: 5.5.38
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/06126805f490aba6f6c107980f673eada0c79e6c
Log: Fix #72656: Object destructor called before constructor
Previous Comments:
------------------------------------------------------------------------
[2021-08-27 11:11:30] cmb@php.net
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>
------------------------------------------------------------------------
[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