mirror of
https://github.com/php/php-src.git
synced 2024-11-28 12:26:37 +08:00
- Set scope when copying a closure with a new this pointer.
This commit is contained in:
parent
a85d2889bc
commit
f408bcef15
29
Zend/tests/closure_036.phpt
Executable file
29
Zend/tests/closure_036.phpt
Executable file
@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
Closure 036: Rebinding closure $this on property access, using scope
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$instance = 0;
|
||||
|
||||
class Test {
|
||||
private $value = 42;
|
||||
function __construct() {
|
||||
global $instance;
|
||||
$this->instance = ++$instance;
|
||||
}
|
||||
}
|
||||
|
||||
$o = new Test;
|
||||
$o->func = function () {
|
||||
var_dump($this->value);
|
||||
};
|
||||
$func = $o->func;
|
||||
$func();
|
||||
|
||||
var_dump($instance);
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
int(42)
|
||||
int(1)
|
||||
===DONE===
|
@ -134,6 +134,9 @@ ZEND_API zval* zend_closure_copy(zval *closure_obj, zval *this_ptr TSRMLS_DC) /*
|
||||
closure->this_ptr = this_ptr;
|
||||
if (this_ptr) {
|
||||
Z_ADDREF_P(this_ptr);
|
||||
closure->func.common.scope = Z_OBJCE_P(this_ptr);
|
||||
} else {
|
||||
closure->func.common.scope = NULL;
|
||||
}
|
||||
return closure_obj;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user