Skip to content

Commit c351768

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #74558: Can't rebind closure returned by Closure::fromCallable()
2 parents e3c63de + 7877389 commit c351768

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.0.0
44

5+
- Core:
6+
. Fixed bug #74558 (Can't rebind closure returned by Closure::fromCallable()).
7+
(cmb)
58

69
12 Nov 2020, PHP 8.0.0RC4
710

Zend/tests/bug70630.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ $x = (new ReflectionFunction("substr"))->getClosure();
77
$x->call(new a);
88
?>
99
--EXPECTF--
10-
Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() in %s on line %d
10+
Warning: Cannot rebind scope of closure created from function in %s on line %d

Zend/tests/bug70685.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ var_dump($c);
1818
Warning: Cannot bind method SplDoublyLinkedList::count() to object of class cls in %s on line %d
1919
NULL
2020

21-
Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() in %s on line %d
21+
Warning: Cannot rebind scope of closure created from method in %s on line %d
2222
NULL

Zend/tests/closure_061.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ bindTo(new Cls, null):
118118
Success!
119119

120120
bindTo(new Cls, Cls::class):
121-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
121+
Cannot rebind scope of closure created from function
122122

123123
bindTo(null, Cls::class):
124-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
124+
Cannot rebind scope of closure created from function
125125

126126
bindTo(null, stdClass::class):
127127
Cannot bind closure to scope of internal class stdClass
@@ -139,10 +139,10 @@ bindTo(new Cls, null):
139139
Success!
140140

141141
bindTo(new Cls, Cls::class):
142-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
142+
Cannot rebind scope of closure created from function
143143

144144
bindTo(null, Cls::class):
145-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
145+
Cannot rebind scope of closure created from function
146146

147147
bindTo(null, stdClass::class):
148148
Cannot bind closure to scope of internal class stdClass
@@ -163,13 +163,13 @@ bindTo(new Cls, Cls::class):
163163
Cannot bind an instance to a static closure
164164

165165
bindTo(null, null):
166-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
166+
Cannot rebind scope of closure created from method
167167

168168
bindTo(null, ClsChild::class):
169-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
169+
Cannot rebind scope of closure created from method
170170

171171
bindTo(null, ClsUnrelated::class):
172-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
172+
Cannot rebind scope of closure created from method
173173

174174
(new Cls)->method()
175175
-------------------
@@ -187,13 +187,13 @@ bindTo(new ClsUnrelated, Cls::class):
187187
Cannot bind method Cls::method() to object of class ClsUnrelated
188188

189189
bindTo(new Cls, null):
190-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
190+
Cannot rebind scope of closure created from method
191191

192192
bindTo(new Cls, ClsUnrelated::class):
193-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
193+
Cannot rebind scope of closure created from method
194194

195195
bindTo(new Cls, ClsChild::class):
196-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
196+
Cannot rebind scope of closure created from method
197197

198198
(new SplDoublyLinkedList)->count()
199199
----------------------------------
@@ -214,10 +214,10 @@ bindTo(null, SplDoublyLinkedList::class):
214214
Cannot unbind $this of method
215215

216216
bindTo(new SplDoublyLinkedList, null):
217-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
217+
Cannot rebind scope of closure created from method
218218

219219
bindTo(new SplDoublyLinkedList, ClsUnrelated::class):
220-
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
220+
Cannot rebind scope of closure created from method
221221

222222
(function() {})()
223223
-----------------

Zend/zend_closures.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ static zend_bool zend_valid_closure_binding(
107107
}
108108

109109
if (is_fake_closure && scope != func->common.scope) {
110-
zend_error(E_WARNING, "Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()");
110+
if (func->common.scope == NULL) {
111+
zend_error(E_WARNING, "Cannot rebind scope of closure created from function");
112+
} else {
113+
zend_error(E_WARNING, "Cannot rebind scope of closure created from method");
114+
}
111115
return 0;
112116
}
113117

0 commit comments

Comments
 (0)