Skip to content

Commit 1c36e33

Browse files
author
dmitry
committed
Fixed bug #36006 (Problem with $this in __destruct())
git-svn-id: http://svn.php.net/repository/php/php-src/php/php-src/branches/PHP_5_0@205370 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent e5ddb0d commit 1c36e33

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44
- Fixed an error in mysqli_fetch_fields (returned NULL instead of an
55
array when row number > field_count). (Georg)
66
- Renamed CachingRecursiveIterator to RecursiveCachingIterator. (Marcus)
7+
- Fixed bug #36006 (Problem with $this in __destruct()). (Dmitry)
78
- Fixed bug #35612 (iis6 Access Violation crash). (Dmitry, alacn.uhahaa)
89
- Fixed bug #35570 (segfault when re-using soap client object). (Dmitry)
910
- FIxed bug #35536 (mysql_field_type() doesn't handle NEWDECIMAL). (Tony)

Zend/tests/bug36006.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #36006 (Problem with $this in __destruct())
3+
--FILE--
4+
<?php
5+
6+
class Person {
7+
public $dad;
8+
public function __destruct() {
9+
$this->dad = null; /* no segfault if this is commented out */
10+
}
11+
}
12+
13+
class Dad extends Person {
14+
public $son;
15+
public function __construct() {
16+
$this->son = new Person;
17+
$this->son->dad = $this; /* no segfault if this is commented out */
18+
}
19+
public function __destruct() {
20+
$this->son = null;
21+
parent::__destruct(); /* segfault here */
22+
}
23+
}
24+
25+
$o = new Dad;
26+
unset($o);
27+
echo "ok\n";
28+
?>
29+
--EXPECT--
30+
ok

Zend/zend_objects_API.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects TS
5252
if (!objects->object_buckets[i].destructor_called) {
5353
objects->object_buckets[i].destructor_called = 1;
5454
if (obj->dtor) {
55+
obj->refcount++;
5556
obj->dtor(obj->object, i TSRMLS_CC);
57+
obj->refcount--;
5658
}
5759
}
5860
}

0 commit comments

Comments
 (0)