Deprecate unbinding $this from non-static closure
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Jul 2019 10:53:09 +0000 (12:53 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 22 Jul 2019 09:39:52 +0000 (11:39 +0200)
Zend/tests/closure_041.phpt
Zend/tests/closure_044.phpt
Zend/tests/closure_046.phpt
Zend/tests/no_class_const_propagation_in_closures.phpt
Zend/zend_closures.c

index 33cf03b14ce77a9e6a98917ffc31203a65611759..cfe4f9487f662ec97e785d8f85d910b228373235 100644 (file)
@@ -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
index c71204b13089a046bad8f1fd9ce420bd60745dcb..225d7540d2a9f45754b4d44e7553d150ac2e8126 100644 (file)
@@ -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)
 
index ef8aff4bbce609ccab0de0a02500e88427786948..e10cc1b57e78ec91a6bb3d6e370564c5680d9fd1 100644 (file)
@@ -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)
 
index e446573b9d8e468e9de305608eaeb921b878a9a0..89d48e2d8359186266f7851fb1b3bb1f4412f866 100644 (file)
@@ -18,7 +18,7 @@ class B {
 }
 
 $f = (new A)->f();
-var_dump($f->bindTo(null, 'B')());
+var_dump($f->bindTo(new B, 'B')());
 
 ?>
 --EXPECT--
index e8688a6fd1ac0707dc75a9a14f3316f6d49cefc8..a8c4a898627fcaa28baac135c0aca69f2b7a1833 100644 (file)
@@ -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) {