1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

Deprecate unbinding $this from non-static closure

This commit is contained in:
Nikita Popov
2019-07-12 12:53:09 +02:00
parent b3f74b0b7d
commit 28cf080701
5 changed files with 14 additions and 3 deletions

View 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

View 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)

View 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)

View 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--

View 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) {