Skip to content

Commit 5a3de00

Browse files
committed
Fix staticness inference
1 parent abb5d54 commit 5a3de00

File tree

11 files changed

+191
-4
lines changed

11 files changed

+191
-4
lines changed

Zend/tests/partial_application/fuzz_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $closure = function($a, $b) {};
77
echo (string) new ReflectionFunction($closure(1, ?));
88
?>
99
--EXPECTF--
10-
Closure [ <user> static function {closure:%s:%d} ] {
10+
Closure [ <user> function {closure:%s:%d} ] {
1111
@@ %s 4 - 4
1212

1313
- Bound Variables [2] {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
PFA of static method is static
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public static function f($a) {
8+
var_dump($a);
9+
}
10+
}
11+
12+
$f = C::f(?);
13+
echo new ReflectionFunction($f), "\n";
14+
$f(1);
15+
16+
$f = (new C)->f(?);
17+
echo new ReflectionFunction($f), "\n";
18+
$f(1);
19+
20+
// Warns
21+
var_dump($f->bindTo(new C));
22+
23+
?>
24+
--EXPECTF--
25+
Closure [ <user> static public method {closure:pfa:%s:9} ] {
26+
@@ %s 9 - 9
27+
28+
- Parameters [1] {
29+
Parameter #0 [ <required> $a ]
30+
}
31+
}
32+
33+
int(1)
34+
Closure [ <user> static public method {closure:pfa:%s:13} ] {
35+
@@ %s 13 - 13
36+
37+
- Parameters [1] {
38+
Parameter #0 [ <required> $a ]
39+
}
40+
}
41+
42+
int(1)
43+
44+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
45+
NULL
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
PFA of instance method is not static
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public function f($a) {
8+
var_dump($this, $this === $a);
9+
}
10+
}
11+
12+
$c = new C();
13+
$f = $c->f(?);
14+
echo new ReflectionFunction($f), "\n";
15+
$f($c);
16+
17+
$c2 = new C();
18+
$f->bindTo($c2)($c2);
19+
20+
?>
21+
--EXPECTF--
22+
Closure [ <user> public method {closure:pfa:%s:10} ] {
23+
@@ %s 10 - 10
24+
25+
- Parameters [1] {
26+
Parameter #0 [ <required> $a ]
27+
}
28+
}
29+
30+
object(C)#%d (0) {
31+
}
32+
bool(true)
33+
object(C)#%d (0) {
34+
}
35+
bool(true)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
PFA of standalone function is static
3+
--FILE--
4+
<?php
5+
6+
function f($a) {
7+
var_dump($a);
8+
}
9+
10+
$f = f(?);
11+
echo new ReflectionFunction($f), "\n";
12+
$f(1);
13+
14+
// Warns
15+
var_dump($f->bindTo(new class {}));
16+
17+
?>
18+
--EXPECTF--
19+
Closure [ <user> static function {closure:pfa:%s:7} ] {
20+
@@ %s 7 - 7
21+
22+
- Parameters [1] {
23+
Parameter #0 [ <required> $a ]
24+
}
25+
}
26+
27+
int(1)
28+
29+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
30+
NULL
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
PFA of non-static closure is not static
3+
--FILE--
4+
<?php
5+
6+
$c = function ($a) {
7+
try {
8+
var_dump($this, $this === $a);
9+
} catch (Error $e) {
10+
var_dump(null, false);
11+
}
12+
};
13+
14+
$f = $c(?);
15+
echo new ReflectionFunction($f), "\n";
16+
$f($c);
17+
18+
$c2 = new class {};
19+
$f->bindTo($c2)($c2);
20+
21+
?>
22+
--EXPECTF--
23+
Closure [ <user> function {closure:pfa:%s:11} ] {
24+
@@ %s 11 - 11
25+
26+
- Bound Variables [1] {
27+
Variable #0 [ $fn ]
28+
}
29+
30+
- Parameters [1] {
31+
Parameter #0 [ <required> $a ]
32+
}
33+
}
34+
35+
NULL
36+
bool(false)
37+
object(class@anonymous)#3 (0) {
38+
}
39+
bool(true)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
PFA of static closure is static
3+
--FILE--
4+
<?php
5+
6+
$c = static function ($a) {
7+
var_dump($a);
8+
};
9+
10+
$f = $c(?);
11+
echo new ReflectionFunction($f), "\n";
12+
$f(1);
13+
14+
// Warns
15+
var_dump($f->bindTo(new class {}));
16+
17+
?>
18+
--EXPECTF--
19+
Closure [ <user> static function {closure:pfa:%s:7} ] {
20+
@@ %s 7 - 7
21+
22+
- Bound Variables [1] {
23+
Variable #0 [ $fn ]
24+
}
25+
26+
- Parameters [1] {
27+
Parameter #0 [ <required> $a ]
28+
}
29+
}
30+
31+
int(1)
32+
33+
Warning: Cannot bind an instance to a static closure, this will be an error in PHP 9 in %s on line %d
34+
NULL
File renamed without changes.
File renamed without changes.
File renamed without changes.

Zend/tests/partial_application/variation_closure_001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ echo (string) new ReflectionFunction($closure2(1, ?));
1414

1515
?>
1616
--EXPECTF--
17-
Closure [ <user> static function {closure:%s:%d} ] {
17+
Closure [ <user> function {closure:%s:%d} ] {
1818
@@ %s 5 - 5
1919

2020
- Bound Variables [2] {
@@ -26,7 +26,7 @@ Closure [ <user> static function {closure:%s:%d} ] {
2626
Parameter #0 [ <required> $b ]
2727
}
2828
}
29-
Closure [ <user> static function {closure:pfa:%s:%d} ] {
29+
Closure [ <user> function {closure:pfa:%s:%d} ] {
3030
@@ %s 10 - 10
3131

3232
- Bound Variables [2] {

0 commit comments

Comments
 (0)