Skip to content

Commit 28cf080

Browse files
committed
Deprecate unbinding $this from non-static closure
1 parent b3f74b0 commit 28cf080

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

Zend/tests/closure_041.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ scoped to A: bool(false)
8080
bound: no
8181
scoped to A: bool(true)
8282
bound: no
83+
84+
Deprecated: Unbinding $this of closure is deprecated in %s on line %d
8385
scoped to A: bool(true)
8486
bound: no
8587
After binding, with same-class instance for the bound ones

Zend/tests/closure_044.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $d = $nonstaticUnscoped->bindTo(new A, 'A'); $d(); echo "\n";
3838
$d = $nonstaticScoped->bindTo(new A, 'A'); $d(); echo "\n";
3939

4040
echo "Done.\n";
41-
--EXPECT--
41+
--EXPECTF--
4242
Before binding
4343
bool(false)
4444
bool(false)
@@ -50,6 +50,8 @@ After binding, null scope, no instance
5050
bool(false)
5151
bool(false)
5252

53+
54+
Deprecated: Unbinding $this of closure is deprecated in %s on line %d
5355
bool(false)
5456
bool(false)
5557

@@ -64,6 +66,8 @@ After binding, with scope, no instance
6466
bool(true)
6567
bool(false)
6668

69+
70+
Deprecated: Unbinding $this of closure is deprecated in %s on line %d
6771
bool(true)
6872
bool(false)
6973

Zend/tests/closure_046.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ echo "After binding, with different instance for the bound one", "\n";
3838
$d = $nonstaticScoped->bindTo(new B, "static"); $d(); echo "\n";
3939

4040
echo "Done.\n";
41-
--EXPECT--
41+
--EXPECTF--
4242
Before binding
4343
bool(false)
4444
bool(false)
@@ -50,6 +50,8 @@ After binding, no instance
5050
bool(false)
5151
bool(false)
5252

53+
54+
Deprecated: Unbinding $this of closure is deprecated in %s on line %d
5355
bool(true)
5456
bool(false)
5557

Zend/tests/no_class_const_propagation_in_closures.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class B {
1818
}
1919

2020
$f = (new A)->f();
21-
var_dump($f->bindTo(null, 'B')());
21+
var_dump($f->bindTo(new B, 'B')());
2222

2323
?>
2424
--EXPECT--

Zend/zend_closures.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ static zend_bool zend_valid_closure_binding(
9090
} else {
9191
zend_error(E_DEPRECATED, "Unbinding $this of a method is deprecated");
9292
}
93+
} else if (!is_fake_closure && !Z_ISUNDEF(closure->this_ptr)) {
94+
// TODO: Only deprecate if it had $this *originally*?
95+
zend_error(E_DEPRECATED, "Unbinding $this of closure is deprecated");
9396
}
9497

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

0 commit comments

Comments
 (0)