summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2015-10-14 12:07:04 +0200
committerAnatol Belski <ab@php.net>2015-10-14 16:15:27 +0200
commit1b5b21539f8f12e6114bd4852438101c8989eabc (patch)
tree5b0670bd6bd80af3b38c4641439f7722e538f881
parent666db28ef25a166bb01c129316ecb7fec1e92532 (diff)
downloadphp-git-php-7.0.0RC5.tar.gz
Do not create a fake Closure for real Closuresphp-7.0.0RC5
That is solved by just returning the Closure as is, which is safe due to Closures being immutable objects
-rw-r--r--Zend/tests/closure_061.phpt33
-rw-r--r--ext/reflection/php_reflection.c7
2 files changed, 39 insertions, 1 deletions
diff --git a/Zend/tests/closure_061.phpt b/Zend/tests/closure_061.phpt
index a87303498e..83ad16d2e1 100644
--- a/Zend/tests/closure_061.phpt
+++ b/Zend/tests/closure_061.phpt
@@ -64,6 +64,15 @@ $tests = [
[new DLL, null],
[new DLL, ClsUnrelated::class],
]],
+
+ [function() {}, [
+ [null, null],
+ [new Cls, null],
+ [new Cls, 'Cls'],
+ [null, 'Cls'],
+ [null, 'stdClass'],
+ [new stdClass, null],
+ ]],
];
set_error_handler(function($errno, $errstr) {
@@ -79,6 +88,9 @@ foreach ($tests as list($fn, $bindings)) {
$c = (new ReflectionFunction($fn))->getClosure();
$fnStr = $fn;
}
+ if ($fn instanceof Closure) {
+ $fnStr = "(function() {})";
+ }
echo "$fnStr()\n" . str_repeat('-', strlen($fnStr) + 2), "\n\n";
@@ -206,3 +218,24 @@ Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure
bindTo(new SplDoublyLinkedList, ClsUnrelated::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
+
+(function() {})()
+-----------------
+
+bindTo(null, null):
+Success!
+
+bindTo(new Cls, null):
+Success!
+
+bindTo(new Cls, Cls::class):
+Success!
+
+bindTo(null, Cls::class):
+Success!
+
+bindTo(null, stdClass::class):
+Cannot bind closure to scope of internal class stdClass
+
+bindTo(new stdClass, null):
+Success!
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index a095120e18..df905bf5cc 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -1762,7 +1762,12 @@ ZEND_METHOD(reflection_function, getClosure)
}
GET_REFLECTION_OBJECT_PTR(fptr);
- zend_create_fake_closure(return_value, fptr, NULL, NULL, NULL);
+ if (!Z_ISUNDEF(intern->obj)) {
+ /* Closures are immutable objects */
+ ZVAL_COPY(return_value, &intern->obj);
+ } else {
+ zend_create_fake_closure(return_value, fptr, NULL, NULL, NULL);
+ }
}
/* }}} */