Skip to content

Commit 637bcd9

Browse files
committed
Infer static for closures
See #19754 (comment)
1 parent 78c997f commit 637bcd9

File tree

16 files changed

+56
-57
lines changed

16 files changed

+56
-57
lines changed

Zend/tests/arrow_functions/005.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class Test {
4040

4141
?>
4242
--EXPECT--
43-
object(Test)#1 (0) {
44-
}
43+
NULL
4544
object(Test)#1 (0) {
4645
}
4746
object(Test)#1 (0) {

Zend/tests/bug75079_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ int(123)
3131

3232
Fatal error: Uncaught Error: Cannot access private property Foo::$bar in %s:%d
3333
Stack trace:
34-
#0 %s(%d): A->{closure:%s:%d}()
34+
#0 %s(%d): A::{closure:%s:%d}()
3535
#1 {main}
3636
thrown in %s on line %d

Zend/tests/closures/closure_020.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object(foo)#%d (2) {
2828
["test":"foo":private]=>
2929
int(3)
3030
["a"]=>
31-
object(Closure)#%d (5) {
31+
object(Closure)#%d (%d) {
3232
["name"]=>
3333
string(%d) "{closure:%s:%d}"
3434
["file"]=>
@@ -40,8 +40,6 @@ object(foo)#%d (2) {
4040
["a"]=>
4141
*RECURSION*
4242
}
43-
["this"]=>
44-
*RECURSION*
4543
}
4644
}
4745
bool(true)

Zend/tests/closures/closure_026.phpt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ object(foo)#%d (1) {
3333
["a"]=>
3434
array(1) {
3535
[0]=>
36-
object(Closure)#%d (4) {
36+
object(Closure)#%d (%d) {
3737
["name"]=>
3838
string(%d) "{closure:%s:%d}"
3939
["file"]=>
4040
string(%d) "%s"
4141
["line"]=>
4242
int(%d)
43-
["this"]=>
44-
*RECURSION*
4543
}
4644
}
4745
}
@@ -50,18 +48,13 @@ int(1)
5048
string(1) "a"
5149
array(1) {
5250
[0]=>
53-
object(Closure)#%d (4) {
51+
object(Closure)#%d (%d) {
5452
["name"]=>
5553
string(%d) "{closure:%s:%d}"
5654
["file"]=>
5755
string(%d) "%s"
5856
["line"]=>
5957
int(%d)
60-
["this"]=>
61-
object(foo)#%d (1) {
62-
["a"]=>
63-
*RECURSION*
64-
}
6558
}
6659
}
6760
int(1)

Zend/tests/closures/closure_040.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,5 @@ try {
3333
$cas->bindTo($a, 'A');
3434

3535
?>
36-
--EXPECTF--
36+
--EXPECT--
3737
Closure::bindTo(): Argument #2 ($newScope) must be of type object|string|null, array given
38-
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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ Warning: Cannot unbind $this of closure using $this, this will be an error in PH
8484
NULL
8585

8686
After binding, with same-class instance for the bound ones
87-
88-
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
8987
scoped to A: bool(false)
9088
bound: A (should be scoped to dummy class)
91-
92-
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
9389
scoped to A: bool(true)
9490
bound: A
9591
After binding, with different instance for the bound ones

Zend/tests/closures/closure_043.phpt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $d = $staticScoped->bindTo(new A, 'A');
3939

4040
echo "Done.\n";
4141
?>
42-
--EXPECTF--
42+
--EXPECT--
4343
Before binding
4444
bool(false)
4545
bool(false)
@@ -55,10 +55,6 @@ bool(false)
5555
bool(false)
5656

5757
After binding, null scope, with instance
58-
59-
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
60-
61-
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
6258
After binding, with scope, no instance
6359
bool(true)
6460
bool(false)
@@ -67,8 +63,4 @@ bool(true)
6763
bool(false)
6864

6965
After binding, with scope, with instance
70-
71-
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
72-
73-
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
7466
Done.

Zend/tests/closures/closure_061.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ bindTo(null, Cls::class):
157157
Success!
158158

159159
bindTo(new Cls, null):
160-
Cannot bind an instance to a static closure, this will be an error in PHP 9
160+
Cannot rebind scope of closure created from method, this will be an error in PHP 9
161161

162162
bindTo(new Cls, Cls::class):
163-
Cannot bind an instance to a static closure, this will be an error in PHP 9
163+
Success!
164164

165165
bindTo(null, null):
166166
Cannot rebind scope of closure created from method, this will be an error in PHP 9

Zend/tests/gc/bug60139.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Foo {
88
public $x;
99

1010
public function __construct() {
11-
$this->x = function() {};
11+
$this->x = function () { $this; };
1212
}
1313
}
1414

@@ -17,7 +17,7 @@ class Bar {
1717

1818
public function __construct() {
1919
$self = $this;
20-
$this->x = function() use ($self) {};
20+
$this->x = function() use ($self) { $this; };
2121
}
2222
}
2323

Zend/tests/return_types/012.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $baz = new foo();
1515
var_dump($baz->bar());
1616
?>
1717
--EXPECTF--
18-
object(Closure)#%d (5) {
18+
object(Closure)#%d (4) {
1919
["name"]=>
2020
string(%d) "{closure:%s:%d}"
2121
["file"]=>
@@ -27,7 +27,4 @@ object(Closure)#%d (5) {
2727
["test"]=>
2828
string(3) "one"
2929
}
30-
["this"]=>
31-
object(foo)#%d (0) {
32-
}
3330
}

0 commit comments

Comments
 (0)