diff options
author | Marcus Boerger <helly@php.net> | 2009-01-04 14:23:29 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2009-01-04 14:23:29 +0000 |
commit | 8e741674afe04248bc8d33746bcb1e1196810db0 (patch) | |
tree | a9d64040d58c7b77a6c0c1723c6103bb9e21b873 | |
parent | 08a25290e7c65c8f0da6f7f4d5cb466524b9bcdd (diff) | |
download | php-git-8e741674afe04248bc8d33746bcb1e1196810db0.tar.gz |
- MFH - Set scope when copying a closure with a new this pointer.
-rwxr-xr-x | Zend/tests/closure_036.phpt | 29 | ||||
-rw-r--r-- | Zend/zend_closures.c | 3 |
2 files changed, 32 insertions, 0 deletions
diff --git a/Zend/tests/closure_036.phpt b/Zend/tests/closure_036.phpt new file mode 100755 index 0000000000..301f8601e2 --- /dev/null +++ b/Zend/tests/closure_036.phpt @@ -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===
\ No newline at end of file diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index 03a0e8516f..a069fd3a52 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -130,6 +130,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; } |