ID:          33348
 Updated by:  [EMAIL PROTECTED]
 Reported By: feldgendler at mail dot ru
-Status:      Open
+Status:      Bogus
 Bug Type:    Zend Engine 2 problem
 PHP Version: 5.0.4
 New Comment:

Please read what Andi one more time:

There is no predefined order in which objects are destroyed. It is
random as object id's are re-used after objects have been destroyed.
There is no way (and I don't think there should be) to change this as
we
are efficiently using existing object space. You have to build your
own
mechanism (which should be quite easy) in order to order certain
destruction processes.

Even with your patch destruction order is random.
Hint: try to reassign $c1 with different object and see the result.


Previous Comments:
------------------------------------------------------------------------

[2005-06-15 09:48:02] feldgendler at mail dot ru

REOPEN
Please consider patching.

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

[2005-06-15 09:47:22] feldgendler at mail dot ru

Sorry for the broken line in the patch above.

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

[2005-06-15 09:46:39] feldgendler at mail dot ru

The answer on that bug was "it's not a bug". Well, I agree, it's not a
bug because the manual does not promise any certain order of
destruction. But I know a way to make it consistent with how it's done
in other object-oriented lanuages -- just apply this simple patch:

--- Zend/zend_objects_API.c.orig 2005-06-15 13:59:55.000000000 +0700
+++ Zend/zend_objects_API.c      2005-06-15 13:59:57.000000000 +0700
@@ -44,7 +44,7 @@
 {
        zend_uint i = 1;

-       for (i = 1; i < objects->top ; i++) {
+       for (i = objects->top - 1; i > 0; i--) {
                if (objects->object_buckets[i].valid) {
                        struct _store_object *obj =
&objects->object_buckets[i].bucket.obj;

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

[2005-06-15 09:43:32] [EMAIL PROTECTED]

Search bug DB before submitting new bugs.
See bug #30823.

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

[2005-06-15 09:39:26] feldgendler at mail dot ru

Description:
------------
If several objects are created in the global scope, their destructors
are called in the same order the objects were created, not in the
reverse order. PHP documentation does not promise anything certain
about the order in which destructors are called, but the common
practice for many object-oriented languages is to call the destructors
in the reverse order. This usually (though not always) is better in
cases when the objects being destroyed depend on each other. I think
that the order of destructor calls for global objects should be reverse
compared to the order of their creation. Actually, the same is already
true for function local variables.

Reproduce code:
---------------
class C1 {
    function __construct() {
        print "Constructing " . get_class($this) . "\n";
    }
    function __destruct() {
        print "Destroying " . get_class($this) . "\n";
    }
}
class C2 {
    function __construct() {
        print "Constructing " . get_class($this) . "\n";
    }
    function __destruct() {
        print "Destroying " . get_class($this) . "\n";
    }
}
$c1 = new C1();
$c2 = new C2();

Expected result:
----------------
Constructing C1
Constructing C2
Destructing C2
Destructing C1

Actual result:
--------------
Constructing C1
Constructing C2
Destructing C1
Destructing C2


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


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

Reply via email to