From: Nikita Popov Date: Mon, 28 Oct 2019 12:24:07 +0000 (+0100) Subject: Remove ability to unbind $this of closures if used X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87fefd165a29091c3cb462431529107189c12d55;p=php Remove ability to unbind $this of closures if used This was deprecated in PHP 7.4, removing it for PHP 8.0. --- diff --git a/UPGRADING b/UPGRADING index 8ef0d14117..ba32d55eef 100644 --- a/UPGRADING +++ b/UPGRADING @@ -39,6 +39,8 @@ PHP 8.0 UPGRADE NOTES . Removed each(). foreach or ArrayIterator should be used instead. . Removed ability to unbind $this from closures that were created from a method, using Closure::fromCallable() or ReflectionMethod::getClosure(). + . Also removed ability to unbind $this from proper closures that contain uses + of $this. . Any array that has a number n as its first numeric key will use n+1 for its next implicit key. Even if n is negative. RFC: https://wiki.php.net/rfc/negative_array_index diff --git a/Zend/tests/closure_041.phpt b/Zend/tests/closure_041.phpt index cfe4f9487f..42fc55dfe7 100644 --- a/Zend/tests/closure_041.phpt +++ b/Zend/tests/closure_041.phpt @@ -48,9 +48,7 @@ echo "After binding, no instance", "\n"; $d = $staticUnscoped->bindTo(null); $d(); echo "\n"; $d = $nonstaticUnscoped->bindTo(null); $d(); echo "\n"; $d = $staticScoped->bindTo(null); $d(); echo "\n"; -$d = $nonstaticScoped->bindTo(null); $d(); echo "\n"; -// $d is still non-static -$d->bindTo($d); +$d = $nonstaticScoped->bindTo(null); var_dump($d); echo "\n"; echo "After binding, with same-class instance for the bound ones", "\n"; $d = $staticUnscoped->bindTo(new A); @@ -81,9 +79,9 @@ 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 +Warning: Cannot unbind $this of closure using $this in %s on line %d +NULL + After binding, with same-class instance for the bound ones Warning: Cannot bind an instance to a static closure in %s on line %d diff --git a/Zend/tests/closure_044.phpt b/Zend/tests/closure_044.phpt index 225d7540d2..a848c0b17a 100644 --- a/Zend/tests/closure_044.phpt +++ b/Zend/tests/closure_044.phpt @@ -23,7 +23,7 @@ $nonstaticScoped(); echo "\n"; echo "After binding, null scope, no instance", "\n"; $d = $nonstaticUnscoped->bindTo(null, null); $d(); echo "\n"; -$d = $nonstaticScoped->bindTo(null, null); $d(); echo "\n"; +$d = $nonstaticScoped->bindTo(null, null); var_dump($d); echo "\n"; echo "After binding, null scope, with instance", "\n"; $d = $nonstaticUnscoped->bindTo(new A, null); $d(); echo "\n"; @@ -31,7 +31,7 @@ $d = $nonstaticScoped->bindTo(new A, null); $d(); echo "\n"; echo "After binding, with scope, no instance", "\n"; $d = $nonstaticUnscoped->bindTo(null, 'A'); $d(); echo "\n"; -$d = $nonstaticScoped->bindTo(null, 'A'); $d(); echo "\n"; +$d = $nonstaticScoped->bindTo(null, 'A'); var_dump($d); echo "\n"; echo "After binding, with scope, with instance", "\n"; $d = $nonstaticUnscoped->bindTo(new A, 'A'); $d(); echo "\n"; @@ -51,9 +51,8 @@ bool(false) bool(false) -Deprecated: Unbinding $this of closure is deprecated in %s on line %d -bool(false) -bool(false) +Warning: Cannot unbind $this of closure using $this in %s on line %d +NULL After binding, null scope, with instance bool(false) @@ -67,9 +66,8 @@ bool(true) bool(false) -Deprecated: Unbinding $this of closure is deprecated in %s on line %d -bool(true) -bool(false) +Warning: Cannot unbind $this of closure using $this in %s on line %d +NULL After binding, with scope, with instance bool(true) diff --git a/Zend/tests/closure_046.phpt b/Zend/tests/closure_046.phpt index e10cc1b57e..7d94df33b6 100644 --- a/Zend/tests/closure_046.phpt +++ b/Zend/tests/closure_046.phpt @@ -26,9 +26,7 @@ $nonstaticScoped(); echo "\n"; echo "After binding, no instance", "\n"; $d = $nonstaticUnscoped->bindTo(null, "static"); $d(); echo "\n"; -$d = $nonstaticScoped->bindTo(null, "static"); $d(); echo "\n"; -// $d is still non-static -$d->bindTo($d); +$d = $nonstaticScoped->bindTo(null, "static"); var_dump($d); echo "\n"; echo "After binding, with same-class instance for the bound one", "\n"; $d = $nonstaticUnscoped->bindTo(new A, "static"); $d(); echo "\n"; @@ -51,9 +49,8 @@ bool(false) bool(false) -Deprecated: Unbinding $this of closure is deprecated in %s on line %d -bool(true) -bool(false) +Warning: Cannot unbind $this of closure using $this in %s on line %d +NULL After binding, with same-class instance for the bound one bool(false) diff --git a/Zend/tests/closure_062.phpt b/Zend/tests/closure_062.phpt index d56b4f0663..b8c0a981be 100644 --- a/Zend/tests/closure_062.phpt +++ b/Zend/tests/closure_062.phpt @@ -48,7 +48,7 @@ Test::staticMethod(); --EXPECTF-- instance scoped, non-static, $this used -Deprecated: Unbinding $this of closure is deprecated in %s on line %d +Warning: Cannot unbind $this of closure using $this in %s on line %d instance scoped, static, $this used instance scoped, non-static, $this not used static scoped, non-static, $this used diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index 26184d3d35..dfd6a06dfc 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -89,8 +89,8 @@ static zend_bool zend_valid_closure_binding( return 0; } else if (!is_fake_closure && !Z_ISUNDEF(closure->this_ptr) && (func->common.fn_flags & ZEND_ACC_USES_THIS)) { - // TODO: Only deprecate if it had $this *originally*? - zend_error(E_DEPRECATED, "Unbinding $this of closure is deprecated"); + zend_error(E_WARNING, "Cannot unbind $this of closure using $this"); + return 0; } if (scope && scope != func->common.scope && scope->type == ZEND_INTERNAL_CLASS) {