]> granicus.if.org Git - php/commitdiff
Fixed bug #36006 (Problem with $this in __destruct())
authorDmitry Stogov <dmitry@php.net>
Mon, 16 Jan 2006 10:12:54 +0000 (10:12 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 16 Jan 2006 10:12:54 +0000 (10:12 +0000)
Zend/tests/bug36006.phpt [new file with mode: 0755]
Zend/zend_objects_API.c

diff --git a/Zend/tests/bug36006.phpt b/Zend/tests/bug36006.phpt
new file mode 100755 (executable)
index 0000000..79f9897
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Bug #36006 (Problem with $this in __destruct())
+--FILE--
+<?php
+
+class Person {
+       public $dad;
+       public function __destruct() {
+               $this->dad = null; /* no segfault if this is commented out */
+       }
+}
+
+class Dad extends Person {
+       public $son;
+       public function __construct() {
+               $this->son = new Person;
+               $this->son->dad = $this; /* no segfault if this is commented out */
+       }
+       public function __destruct() {
+               $this->son = null;
+               parent::__destruct(); /* segfault here */
+       }
+}
+
+$o = new Dad;
+unset($o);
+echo "ok\n";
+?>
+--EXPECT--
+ok
index 59e7b3317b58c577dc4bdf73ac64af622548c751..e7084f013b8d028f8433319bf1d3d6d2942b9028 100644 (file)
@@ -52,7 +52,9 @@ ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects TS
                        if (!objects->object_buckets[i].destructor_called) {
                                objects->object_buckets[i].destructor_called = 1;
                                if (obj->dtor && obj->object) {
+                                       obj->refcount++;
                                        obj->dtor(obj->object, i TSRMLS_CC);
+                                       obj->refcount--;
                                }
                        }
                }