mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
Remove ability to unbind $this of closures if used
This was deprecated in PHP 7.4, removing it for PHP 8.0.
This commit is contained in:
parent
26579db403
commit
87fefd165a
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user