Skip to content

Commit 4eb5db2

Browse files
committed
Forbid unbinding $this from methods
1 parent 23a5be3 commit 4eb5db2

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

UPGRADING

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ PHP 8.0 UPGRADE NOTES
3030
argument to define() may no longer be true.
3131
. Removed create_function(). Anonymous functions may be used instead.
3232
. Removed each(). foreach or ArrayIterator should be used instead.
33+
. Removed ability to unbind $this from closures that were created from a
34+
method, using Closure::fromCallable() or ReflectionMethod::getClosure().
3335

3436
- Filter:
3537
. The FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED flags for the

Zend/tests/bug70681.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ var_dump($c("foo"));
1212

1313
?>
1414
--EXPECTF--
15-
Warning: Cannot unbind $this of internal method in %s on line %d
15+
Warning: Cannot unbind $this of method in %s on line %d
1616
int(3)

Zend/tests/closure_061.phpt

+3-5
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure
175175
-------------------
176176

177177
bindTo(null, Cls::class):
178-
Unbinding $this of a method is deprecated
179-
180-
Success!
178+
Cannot unbind $this of method
181179

182180
bindTo(new Cls, Cls::class):
183181
Success!
@@ -210,10 +208,10 @@ bindTo(new ClsUnrelated, SplDoublyLinkedList::class):
210208
Cannot bind method SplDoublyLinkedList::count() to object of class ClsUnrelated
211209

212210
bindTo(null, null):
213-
Cannot unbind $this of internal method
211+
Cannot unbind $this of method
214212

215213
bindTo(null, SplDoublyLinkedList::class):
216-
Cannot unbind $this of internal method
214+
Cannot unbind $this of method
217215

218216
bindTo(new SplDoublyLinkedList, null):
219217
Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()

Zend/zend_closures.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ static zend_bool zend_valid_closure_binding(
8484
}
8585
} else if (is_fake_closure && func->common.scope
8686
&& !(func->common.fn_flags & ZEND_ACC_STATIC)) {
87-
if (func->type == ZEND_INTERNAL_FUNCTION) {
88-
zend_error(E_WARNING, "Cannot unbind $this of internal method");
89-
return 0;
90-
} else {
91-
zend_error(E_DEPRECATED, "Unbinding $this of a method is deprecated");
92-
}
87+
zend_error(E_WARNING, "Cannot unbind $this of method");
88+
return 0;
9389
}
9490

9591
if (scope && scope != func->common.scope && scope->type == ZEND_INTERNAL_CLASS) {

0 commit comments

Comments
 (0)