Edit report at https://bugs.php.net/bug.php?id=36759&edit=1
ID: 36759
Updated by: cmb@php.net
Reported by: alexander dot v at zend dot com
Summary: Objects destructors are invoked in wrong order when
script is finished
-Status: Open
+Status: Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: all
PHP Version: 5CVS-2006-03-16 (snap)
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Is this still an issue with any of the actively supported PHP
versions[1]?
[1] <https://www.php.net/supported-versions.php>
Previous Comments:
------------------------------------------------------------------------
[2014-03-09 11:55:54] ocramius at gmail dot com
Never mind, I've misread the test and was considering "Bar extends Foo" (isn't
an inheritance)
------------------------------------------------------------------------
[2014-03-09 11:47:58] ocramius at gmail dot com
Is the scope violation supposed to throw a fatal? While discussing with others, it seems like it is
a copy-paste mistake.
It seems strange to me that PHP is not preventing access to that private property in the child
class' __destruct() method.
If it is a copy-paste mistake, then this spawns another bug.
------------------------------------------------------------------------
[2013-02-20 09:12:34] reeze@php.net
Sorry I just try to reproduce, but didn't try the later script.
------------------------------------------------------------------------
[2013-02-20 09:10:49] reeze@php.net
I seems been fixed already, see: http://3v4l.org/b2JWc
------------------------------------------------------------------------
[2011-03-21 03:04:57] tstarling at wikimedia dot org
r216213 fixes that one test case, but it seems like the actual complaint here is that objects stored
in member variables are destroyed before the objects that reference them. I can see three problems
with r216213. Two of them mean that this bug is not fixed, and the third causes another bug.
1. It assumes that all objects which hold references to other objects will be in the global symbol
table. For objects that aren't in the global symbol table, it fails. For example if you take
the test case and replace this:
$y = new Bar();
$x = new Foo($y);
with this:
function foo() {
static $x, $y;
$y = new Bar();
$x = new Foo($y);
}
foo();
then the destructors are called in the wrong order.
2. It only deletes objects which have a reference count of 1. When a zval is referred to by two
symbol table entries, both symbol table entries point to the same zval, and both have a reference
count of 2, so neither is deleted. So if you replace the same part of the test case with:
$y = new Bar();
$x = new Foo($y);
$z = $x;
then the destructors are called in the wrong order.
3. It deletes variables, instead of just calling __destruct() on them as expected. This was a hack
to reuse the reference-counting code in zval_ptr_dtor(). It's unnecessary and causes several
user-visible side effects, such as bug #54157.
------------------------------------------------------------------------
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=36759
--
Edit this bug report at https://bugs.php.net/bug.php?id=36759&edit=1