diff --git a/Zend/tests/closure_041.phpt b/Zend/tests/closure_041.phpt index 33cf03b14ce..cfe4f9487f6 100644 --- a/Zend/tests/closure_041.phpt +++ b/Zend/tests/closure_041.phpt @@ -80,6 +80,8 @@ scoped to A: bool(false) bound: no scoped to A: bool(true) bound: no + +Deprecated: Unbinding $this of closure is deprecated in %s on line %d scoped to A: bool(true) bound: no After binding, with same-class instance for the bound ones diff --git a/Zend/tests/closure_044.phpt b/Zend/tests/closure_044.phpt index c71204b1308..225d7540d2a 100644 --- a/Zend/tests/closure_044.phpt +++ b/Zend/tests/closure_044.phpt @@ -38,7 +38,7 @@ $d = $nonstaticUnscoped->bindTo(new A, 'A'); $d(); echo "\n"; $d = $nonstaticScoped->bindTo(new A, 'A'); $d(); echo "\n"; echo "Done.\n"; ---EXPECT-- +--EXPECTF-- Before binding bool(false) bool(false) @@ -50,6 +50,8 @@ After binding, null scope, no instance bool(false) bool(false) + +Deprecated: Unbinding $this of closure is deprecated in %s on line %d bool(false) bool(false) @@ -64,6 +66,8 @@ After binding, with scope, no instance bool(true) bool(false) + +Deprecated: Unbinding $this of closure is deprecated in %s on line %d bool(true) bool(false) diff --git a/Zend/tests/closure_046.phpt b/Zend/tests/closure_046.phpt index ef8aff4bbce..e10cc1b57e7 100644 --- a/Zend/tests/closure_046.phpt +++ b/Zend/tests/closure_046.phpt @@ -38,7 +38,7 @@ echo "After binding, with different instance for the bound one", "\n"; $d = $nonstaticScoped->bindTo(new B, "static"); $d(); echo "\n"; echo "Done.\n"; ---EXPECT-- +--EXPECTF-- Before binding bool(false) bool(false) @@ -50,6 +50,8 @@ After binding, no instance bool(false) bool(false) + +Deprecated: Unbinding $this of closure is deprecated in %s on line %d bool(true) bool(false) diff --git a/Zend/tests/no_class_const_propagation_in_closures.phpt b/Zend/tests/no_class_const_propagation_in_closures.phpt index e446573b9d8..89d48e2d835 100644 --- a/Zend/tests/no_class_const_propagation_in_closures.phpt +++ b/Zend/tests/no_class_const_propagation_in_closures.phpt @@ -18,7 +18,7 @@ class B { } $f = (new A)->f(); -var_dump($f->bindTo(null, 'B')()); +var_dump($f->bindTo(new B, 'B')()); ?> --EXPECT-- diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index e8688a6fd1a..a8c4a898627 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -90,6 +90,9 @@ static zend_bool zend_valid_closure_binding( } else { zend_error(E_DEPRECATED, "Unbinding $this of a method is deprecated"); } + } else if (!is_fake_closure && !Z_ISUNDEF(closure->this_ptr)) { + // TODO: Only deprecate if it had $this *originally*? + zend_error(E_DEPRECATED, "Unbinding $this of closure is deprecated"); } if (scope && scope != func->common.scope && scope->type == ZEND_INTERNAL_CLASS) {