Merge branch 'PHP-7.4' into PHP-8.0

* PHP-7.4:
  Fix #74558: Can't rebind closure returned by Closure::fromCallable()
This commit is contained in:
Christoph M. Becker 2020-11-16 14:33:45 +01:00
commit c351768e4f
5 changed files with 22 additions and 15 deletions

3
NEWS
View file

@ -2,6 +2,9 @@ PHP NEWS
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.0.0 ?? ??? ????, PHP 8.0.0
- Core:
. Fixed bug #74558 (Can't rebind closure returned by Closure::fromCallable()).
(cmb)
12 Nov 2020, PHP 8.0.0RC4 12 Nov 2020, PHP 8.0.0RC4

View file

@ -7,4 +7,4 @@ $x = (new ReflectionFunction("substr"))->getClosure();
$x->call(new a); $x->call(new a);
?> ?>
--EXPECTF-- --EXPECTF--
Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() in %s on line %d Warning: Cannot rebind scope of closure created from function in %s on line %d

View file

@ -18,5 +18,5 @@ var_dump($c);
Warning: Cannot bind method SplDoublyLinkedList::count() to object of class cls in %s on line %d Warning: Cannot bind method SplDoublyLinkedList::count() to object of class cls in %s on line %d
NULL NULL
Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() in %s on line %d Warning: Cannot rebind scope of closure created from method in %s on line %d
NULL NULL

View file

@ -118,10 +118,10 @@ bindTo(new Cls, null):
Success! Success!
bindTo(new Cls, Cls::class): bindTo(new Cls, Cls::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from function
bindTo(null, Cls::class): bindTo(null, Cls::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from function
bindTo(null, stdClass::class): bindTo(null, stdClass::class):
Cannot bind closure to scope of internal class stdClass Cannot bind closure to scope of internal class stdClass
@ -139,10 +139,10 @@ bindTo(new Cls, null):
Success! Success!
bindTo(new Cls, Cls::class): bindTo(new Cls, Cls::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from function
bindTo(null, Cls::class): bindTo(null, Cls::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from function
bindTo(null, stdClass::class): bindTo(null, stdClass::class):
Cannot bind closure to scope of internal class stdClass Cannot bind closure to scope of internal class stdClass
@ -163,13 +163,13 @@ bindTo(new Cls, Cls::class):
Cannot bind an instance to a static closure Cannot bind an instance to a static closure
bindTo(null, null): bindTo(null, null):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from method
bindTo(null, ClsChild::class): bindTo(null, ClsChild::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from method
bindTo(null, ClsUnrelated::class): bindTo(null, ClsUnrelated::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from method
(new Cls)->method() (new Cls)->method()
------------------- -------------------
@ -187,13 +187,13 @@ bindTo(new ClsUnrelated, Cls::class):
Cannot bind method Cls::method() to object of class ClsUnrelated Cannot bind method Cls::method() to object of class ClsUnrelated
bindTo(new Cls, null): bindTo(new Cls, null):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from method
bindTo(new Cls, ClsUnrelated::class): bindTo(new Cls, ClsUnrelated::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from method
bindTo(new Cls, ClsChild::class): bindTo(new Cls, ClsChild::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from method
(new SplDoublyLinkedList)->count() (new SplDoublyLinkedList)->count()
---------------------------------- ----------------------------------
@ -214,10 +214,10 @@ bindTo(null, SplDoublyLinkedList::class):
Cannot unbind $this of method Cannot unbind $this of method
bindTo(new SplDoublyLinkedList, null): bindTo(new SplDoublyLinkedList, null):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from method
bindTo(new SplDoublyLinkedList, ClsUnrelated::class): bindTo(new SplDoublyLinkedList, ClsUnrelated::class):
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() Cannot rebind scope of closure created from method
(function() {})() (function() {})()
----------------- -----------------

View file

@ -107,7 +107,11 @@ static zend_bool zend_valid_closure_binding(
} }
if (is_fake_closure && scope != func->common.scope) { if (is_fake_closure && scope != func->common.scope) {
zend_error(E_WARNING, "Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()"); if (func->common.scope == NULL) {
zend_error(E_WARNING, "Cannot rebind scope of closure created from function");
} else {
zend_error(E_WARNING, "Cannot rebind scope of closure created from method");
}
return 0; return 0;
} }