Skip to content

Commit 94a88c6

Browse files
committed
Squashed changes
1 parent 0bbb3ce commit 94a88c6

81 files changed

Lines changed: 1389 additions & 516 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Zend/Optimizer/zend_call_graph.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ ZEND_API void zend_analyze_calls(zend_arena **arena, zend_script *script, uint32
147147
call_info->named_args = true;
148148
break;
149149
}
150-
if (opline->opcode == ZEND_SEND_PLACEHOLDER
151-
&& opline->op1.num == ZEND_PLACEHOLDER_VARIADIC) {
152-
break;
153-
}
154150

155151
uint32_t num = opline->op2.num;
156152
if (num > 0) {

Zend/tests/partial_application/compile_errors_006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
PFA compile errors: can not use unpacking in PFA, including with variadic placeholdres
2+
PFA compile errors: can not use unpacking in PFA, including with variadic placeholders
33
--FILE--
44
<?php
55
foo(...["foo" => "bar"], ...);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
PFAs may emit deprecation warnings
3+
--FILE--
4+
<?php
5+
6+
#[Deprecated] function f($a) {
7+
}
8+
9+
$f = f(?);
10+
$f(1);
11+
12+
?>
13+
--EXPECTF--
14+
Deprecated: Function f() is deprecated in %s on line %d

Zend/tests/partial_application/errors_003.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ try {
6262
printf("%s: %s\n", $ex::class, $ex->getMessage());
6363
}
6464

65-
try {
66-
$usleep(1, 2);
67-
} catch (Error $ex) {
68-
printf("%s: %s\n", $ex::class, $ex->getMessage());
69-
}
65+
$usleep(1, 2);
66+
7067
?>
7168
--EXPECTF--
7269
ArgumentCountError: Too few arguments to function {closure:%s:%d}(), 0 passed in %s on line %d and exactly 1 expected

Zend/tests/partial_application/errors_006.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ PFA errors: Some internal function parameters have UNKNOWN default value
33
--FILE--
44
<?php
55

6+
$f = array_keys(?, 42);
7+
var_dump($f([41, 42, 43]));
8+
9+
$f = array_keys(?, '42', true);
10+
var_dump($f([41, 42, 43]));
11+
12+
$f = array_keys(?, '42', strict: ?);
13+
var_dump($f([41, 42, 43], false));
14+
var_dump($f([41, 42, 43], true));
15+
616
try {
717
// fn (array $array) => array_keys($array, ???, true)
818
$f = array_keys(?, strict: true);
@@ -19,5 +29,17 @@ try {
1929

2030
?>
2131
--EXPECT--
32+
array(1) {
33+
[0]=>
34+
int(1)
35+
}
36+
array(0) {
37+
}
38+
array(1) {
39+
[0]=>
40+
int(1)
41+
}
42+
array(0) {
43+
}
2244
ArgumentCountError: array_keys(): Argument #2 ($filter_value) must be passed explicitly, because the default value is not known
2345
ArgumentCountError: array_keys(): Argument #2 ($filter_value) must be passed explicitly, because the default value is not known

Zend/tests/partial_application/function_name.phpt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,36 @@ Partial application function name
55

66
function g($a) {}
77

8+
class C {
9+
static function m() {
10+
echo "# From a method:\n";
11+
var_dump((new ReflectionFunction(g(?)))->getName());
12+
}
13+
}
14+
815
function f() {
16+
echo "# From a function:\n";
917
var_dump((new ReflectionFunction(g(?)))->getName());
18+
19+
echo "# Declared on same line:\n";
20+
[$a, $b] = [g(?), g(?)];
21+
var_dump((new ReflectionFunction($a))->getName(), (new ReflectionFunction($b))->getName());
1022
}
1123

1224
f();
25+
C::m();
1326

27+
echo "# From global scope:\n";
1428
var_dump((new ReflectionFunction(g(?)))->getName());
1529

1630
?>
1731
--EXPECTF--
18-
string(%d) "{closure:pfa:f():6}"
19-
string(%d) "{closure:pfa:%sfunction_name.php:11}"
32+
# From a function:
33+
string(20) "{closure:pfa:f():14}"
34+
# Declared on same line:
35+
string(20) "{closure:pfa:f():17}"
36+
string(20) "{closure:pfa:f():17}"
37+
# From a method:
38+
string(22) "{closure:pfa:C::m():8}"
39+
# From global scope:
40+
string(%d) "{closure:pfa:%sfunction_name.php:25}"

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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
PFA: instance polymorphism
3+
--FILE--
4+
<?php
5+
6+
class P {
7+
public function m(string $a): void {
8+
echo __METHOD__, PHP_EOL;
9+
var_dump($a);
10+
}
11+
12+
13+
public function get() {
14+
/* The method is resolved before creating the PFA, and captured by the
15+
* PFA. We use the signature of the resolved method. */
16+
return $this->m(?);
17+
}
18+
}
19+
20+
class C extends P {
21+
public function m(string|array $b): void {
22+
echo __METHOD__, PHP_EOL;
23+
var_dump($b);
24+
}
25+
}
26+
27+
for ($i = 0; $i < 2; $i++) {
28+
(new P())->get()(a: 'a');
29+
(new C())->get()(b: []);
30+
}
31+
32+
?>
33+
--EXPECT--
34+
P::m
35+
string(1) "a"
36+
C::m
37+
array(0) {
38+
}
39+
P::m
40+
string(1) "a"
41+
C::m
42+
array(0) {
43+
}

Zend/tests/partial_application/magic_001.phpt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ __call() can be partially applied
33
--FILE--
44
<?php
55
class Foo {
6-
public function __call($method, $args) {
6+
public function __call($method, $arguments) {
77
printf("%s::%s\n", __CLASS__, $method);
88

9-
var_dump(...$args);
9+
var_dump(...$arguments);
1010
}
1111
}
1212

@@ -22,19 +22,15 @@ try {
2222
printf("%s: %s\n", $ex::class, $ex->getMessage());
2323
}
2424

25-
try {
26-
$bar(1, 2);
27-
} catch (Error $ex) {
28-
printf("%s: %s\n", $ex::class, $ex->getMessage());
29-
}
30-
25+
$bar(1, 2);
3126
$bar(1);
3227

3328
$bar = $foo->method(?, ...);
3429

3530
echo (string) new ReflectionFunction($bar);
3631

3732
$bar(10);
33+
$bar(10, 20);
3834

3935
$bar = $foo->method(new Foo, ...);
4036

@@ -47,7 +43,7 @@ Closure [ <user> public method {closure:%s:%d} ] {
4743
@@ %s 12 - 12
4844

4945
- Parameters [1] {
50-
Parameter #0 [ <required> $args0 ]
46+
Parameter #0 [ <required> mixed $arguments0 ]
5147
}
5248
}
5349
ArgumentCountError: Too few arguments to function Foo::{closure:%s:%d}(), 0 passed in %s on line %d and exactly 1 expected
@@ -56,24 +52,27 @@ int(1)
5652
Foo::method
5753
int(1)
5854
Closure [ <user> public method {closure:%s:%d} ] {
59-
@@ %s 30 - 30
55+
@@ %s 25 - 25
6056

6157
- Parameters [2] {
62-
Parameter #0 [ <required> $args0 ]
63-
Parameter #1 [ <optional> ...$args ]
58+
Parameter #0 [ <required> mixed $arguments0 ]
59+
Parameter #1 [ <optional> mixed ...$arguments ]
6460
}
6561
}
6662
Foo::method
6763
int(10)
64+
Foo::method
65+
int(10)
66+
int(20)
6867
Closure [ <user> public method {closure:%s:%d} ] {
69-
@@ %s 36 - 36
68+
@@ %s 32 - 32
7069

7170
- Bound Variables [1] {
72-
Variable #0 [ $args0 ]
71+
Variable #0 [ $arguments0 ]
7372
}
7473

7574
- Parameters [1] {
76-
Parameter #0 [ <optional> ...$args ]
75+
Parameter #0 [ <optional> mixed ...$arguments ]
7776
}
7877
}
7978
Foo::method

Zend/tests/partial_application/magic_002.phpt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ __callStatic() can be partially applied
33
--FILE--
44
<?php
55
class Foo {
6-
public static function __callStatic($method, $args) {
6+
public static function __callStatic($method, $arguments) {
77
printf("%s::%s\n", __CLASS__, $method);
88

9-
var_dump(...$args);
9+
var_dump(...$arguments);
1010
}
1111
}
1212

@@ -15,12 +15,14 @@ $bar = Foo::method(?);
1515
echo (string) new ReflectionFunction($bar);
1616

1717
$bar(1);
18+
$bar(1, 2);
1819

1920
$bar = Foo::method(?, ...);
2021

2122
echo (string) new ReflectionFunction($bar);
2223

2324
$bar(10);
25+
$bar(10, 20);
2426

2527
$bar = Foo::method(new Foo,...);
2628

@@ -33,30 +35,35 @@ Closure [ <user> static public method {closure:%s:%d} ] {
3335
@@ %s 10 - 10
3436

3537
- Parameters [1] {
36-
Parameter #0 [ <required> $args0 ]
38+
Parameter #0 [ <required> mixed $arguments0 ]
3739
}
3840
}
3941
Foo::method
4042
int(1)
43+
Foo::method
44+
int(1)
4145
Closure [ <user> static public method {closure:%s:%d} ] {
42-
@@ %s 16 - 16
46+
@@ %s 17 - 17
4347

4448
- Parameters [2] {
45-
Parameter #0 [ <required> $args0 ]
46-
Parameter #1 [ <optional> ...$args ]
49+
Parameter #0 [ <required> mixed $arguments0 ]
50+
Parameter #1 [ <optional> mixed ...$arguments ]
4751
}
4852
}
4953
Foo::method
5054
int(10)
55+
Foo::method
56+
int(10)
57+
int(20)
5158
Closure [ <user> static public method {closure:%s:%d} ] {
52-
@@ %s 22 - 22
59+
@@ %s 24 - 24
5360

5461
- Bound Variables [1] {
55-
Variable #0 [ $args0 ]
62+
Variable #0 [ $arguments0 ]
5663
}
5764

5865
- Parameters [1] {
59-
Parameter #0 [ <optional> ...$args ]
66+
Parameter #0 [ <optional> mixed ...$arguments ]
6067
}
6168
}
6269
Foo::method

0 commit comments

Comments
 (0)