]> granicus.if.org Git - php/commitdiff
Remove ability to unbind $this of closures if used
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 28 Oct 2019 12:24:07 +0000 (13:24 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 28 Oct 2019 12:24:07 +0000 (13:24 +0100)
This was deprecated in PHP 7.4, removing it for PHP 8.0.

UPGRADING
Zend/tests/closure_041.phpt
Zend/tests/closure_044.phpt
Zend/tests/closure_046.phpt
Zend/tests/closure_062.phpt
Zend/zend_closures.c

index 8ef0d14117911c207557c60a17e8366e25bb350d..ba32d55eef93e5278a46c9b9276c8bae82cec23b 100644 (file)
--- 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
index cfe4f9487f662ec97e785d8f85d910b228373235..42fc55dfe773c2352cb68f13b1f84b0f5f3f4d14 100644 (file)
@@ -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
index 225d7540d2a9f45754b4d44e7553d150ac2e8126..a848c0b17aa284f95d6cda968eb67a51f60a633f 100644 (file)
@@ -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)
index e10cc1b57e78ec91a6bb3d6e370564c5680d9fd1..7d94df33b635858ce9ace2beb85a50b45a9a4dc4 100644 (file)
@@ -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)
index d56b4f06637aebb0e9731ef2a9552e20ce872aa7..b8c0a981be5276f4806916611df69faa0d6a7187 100644 (file)
@@ -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
index 26184d3d3598570fc7b5821ab6e8476cd4340538..dfd6a06dfce7a8d74a7561c90124123b1dc1fc97 100644 (file)
@@ -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) {