Bug #36759 [Com]: Objects destructors are invoked in wrong order when script is finished

From: Date: Sun, 09 Mar 2014 11:48:00 +0000
Subject: Bug #36759 [Com]: Objects destructors are invoked in wrong order when script is finished
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184632@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=36759&edit=1

 ID:                 36759
 Comment by:         ocramius at gmail dot com
 Reported by:        alexander dot v at zend dot com
 Summary:            Objects destructors are invoked in wrong order when
                     script is finished
 Status:             Assigned
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   all
 PHP Version:        5CVS-2006-03-16 (snap)
 Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2011-03-21 01:35:02] stas@php.net

According to Tim Starling, still happens, details to follow soon.

------------------------------------------------------------------------
[2006-07-12 08:57:50] dmitry@php.net

Fixed in CVS HEAD and PHP_5_2.

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


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


Thread (14 messages)

« previous php.bugs (#184632) next »