Skip to content

Commit 0c69246

Browse files
Deprecate closure binding issues
1 parent c98b173 commit 0c69246

15 files changed

+57
-47
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PHP NEWS
1212
error in PHP 9. (alexandre-daubois)
1313
. Fixed OSS-Fuzz #439125710 (Pipe cannot be used in write context).
1414
(nielsdos)
15+
. Various closure binding issues are now deprecated. (alexandre-daubois)
1516

1617
- ODBC:
1718
. Remove ODBCVER and assume ODBC 3.5. (Calvin Buckley)

UPGRADING

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,15 @@ PHP 8.5 UPGRADE NOTES
349349
. Constant redeclaration is deprecated and that behavior will trigger an
350350
error in PHP 9.
351351
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_constant_redeclaration
352+
. The following closure binding issues, which already emit an E_WARNING, are now deprecated:
353+
- Binding an instance to a static closure
354+
- Binding methods to objects that are not instances of the class
355+
(or subclass) that the method is defined
356+
- Unbinding $this from a method
357+
- Unbinding $this from a closure that uses `$this`
358+
- Binding a closure to the scope of an internal class
359+
- Rebinding the scope of a closure created from a function or method
360+
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_closure_binding_issues
352361

353362
- Curl:
354363
. The curl_close() function has been deprecated, as CurlHandle objects are

Zend/tests/bug70681.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ var_dump($c("foo"));
1212

1313
?>
1414
--EXPECTF--
15-
Warning: Cannot unbind $this of method in %s on line %d
15+
Warning: Cannot unbind $this of method, this will be an error in PHP 9 in %s on line %d
1616
int(3)

Zend/tests/closures/bug70630.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ $x = (new ReflectionFunction("substr"))->getClosure();
77
$x->call(new a);
88
?>
99
--EXPECTF--
10-
Warning: Cannot rebind scope of closure created from function in %s on line %d
10+
Warning: Cannot rebind scope of closure created from function, this will be an error in PHP 9 in %s on line %d

Zend/tests/closures/bug70685.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ var_dump($c);
1515

1616
?>
1717
--EXPECTF--
18-
Warning: Cannot bind method SplDoublyLinkedList::count() to object of class cls in %s on line %d
18+
Warning: Cannot bind method SplDoublyLinkedList::count() to object of class cls, this will be an error in PHP 9 in %s on line %d
1919
NULL
2020

21-
Warning: Cannot rebind scope of closure created from method in %s on line %d
21+
Warning: Cannot rebind scope of closure created from method, this will be an error in PHP 9 in %s on line %d
2222
NULL

Zend/tests/closures/closure_040.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ $cas->bindTo($a, 'A');
3636
--EXPECTF--
3737
Closure::bindTo(): Argument #2 ($newScope) must be of type object|string|null, array given
3838

39-
Warning: Cannot bind an instance to a static closure in %s on line %d
39+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d

Zend/tests/closures/closure_041.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ bound: no
8080
scoped to A: bool(true)
8181
bound: no
8282

83-
Warning: Cannot unbind $this of closure using $this in %s on line %d
83+
Warning: Cannot unbind $this of closure using $this, this will be an error in PHP 9 in %s on line %d
8484
NULL
8585

8686
After binding, with same-class instance for the bound ones
8787

88-
Warning: Cannot bind an instance to a static closure in %s on line %d
88+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
8989
scoped to A: bool(false)
9090
bound: A (should be scoped to dummy class)
9191

92-
Warning: Cannot bind an instance to a static closure in %s on line %d
92+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
9393
scoped to A: bool(true)
9494
bound: A
9595
After binding, with different instance for the bound ones

Zend/tests/closures/closure_043.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ bool(false)
5656

5757
After binding, null scope, with instance
5858

59-
Warning: Cannot bind an instance to a static closure in %s on line %d
59+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
6060

61-
Warning: Cannot bind an instance to a static closure in %s on line %d
61+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
6262
After binding, with scope, no instance
6363
bool(true)
6464
bool(false)
@@ -68,7 +68,7 @@ bool(false)
6868

6969
After binding, with scope, with instance
7070

71-
Warning: Cannot bind an instance to a static closure in %s on line %d
71+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
7272

73-
Warning: Cannot bind an instance to a static closure in %s on line %d
73+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
7474
Done.

Zend/tests/closures/closure_044.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool(false)
5252
bool(false)
5353

5454

55-
Warning: Cannot unbind $this of closure using $this in %s on line %d
55+
Warning: Cannot unbind $this of closure using $this, this will be an error in PHP 9 in %s on line %d
5656
NULL
5757

5858
After binding, null scope, with instance
@@ -67,7 +67,7 @@ bool(true)
6767
bool(false)
6868

6969

70-
Warning: Cannot unbind $this of closure using $this in %s on line %d
70+
Warning: Cannot unbind $this of closure using $this, this will be an error in PHP 9 in %s on line %d
7171
NULL
7272

7373
After binding, with scope, with instance

Zend/tests/closures/closure_046.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool(false)
5050
bool(false)
5151

5252

53-
Warning: Cannot unbind $this of closure using $this in %s on line %d
53+
Warning: Cannot unbind $this of closure using $this, this will be an error in PHP 9 in %s on line %d
5454
NULL
5555

5656
After binding, with same-class instance for the bound one

0 commit comments

Comments
 (0)