From: Marcus Boerger Date: Sun, 4 Jan 2009 14:22:51 +0000 (+0000) Subject: - Set scope when copying a closure with a new this pointer. X-Git-Tag: php-5.4.0alpha1~191^2~4645 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f408bcef15c7d4c7679f9d7c4adf2a59050f16ae;p=php - Set scope when copying a closure with a new this pointer. --- 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-- +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 e137bbd461..aa4ff21379 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -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; }