Skip to content

Commit b7bb803

Browse files
committed
- MFH Fix refcounting
1 parent 0e13165 commit b7bb803

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Zend/tests/closure_035.phpt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Closure 035: Rebinding closure $this on property access
3+
--FILE--
4+
<?php
5+
6+
$instance = 0;
7+
8+
class Test {
9+
function __construct() {
10+
global $instance;
11+
$this->instance = ++$instance;
12+
}
13+
}
14+
15+
$o = new Test;
16+
$o->func = function () {
17+
var_dump($this);
18+
};
19+
$func = $o->func;
20+
$func();
21+
22+
var_dump($instance);
23+
?>
24+
===DONE===
25+
--EXPECTF--
26+
object(Test)#%d (2) {
27+
["instance"]=>
28+
int(1)
29+
["func"]=>
30+
object(Closure)#%d (1) {
31+
["this"]=>
32+
object(Test)#%d (2) {
33+
["instance"]=>
34+
int(1)
35+
["func"]=>
36+
object(Closure)#2 (1) {
37+
["this"]=>
38+
*RECURSION*
39+
}
40+
}
41+
}
42+
}
43+
int(1)
44+
===DONE===

Zend/zend_closures.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ ZEND_API zval* zend_closure_copy(zval *closure_obj, zval *this_ptr TSRMLS_DC) /*
124124

125125
zval_copy_ctor(closure_obj);
126126
closure = (zend_closure *)zend_object_store_get_object(closure_obj TSRMLS_CC);
127+
if (closure->this_ptr) {
128+
zval_ptr_dtor(&closure->this_ptr);
129+
}
127130
closure->this_ptr = this_ptr;
131+
if (this_ptr) {
132+
Z_ADDREF_P(this_ptr);
133+
}
128134
return closure_obj;
129135
}
130136
/* }}} */

0 commit comments

Comments
 (0)