Skip to content

Commit 0a88cef

Browse files
committed
Add tests
1 parent dd1eec2 commit 0a88cef

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
PFA pipe optimization: PFA with unknown named parameter can be optimized
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.opt_debug_level=0x20000
7+
opcache.enable=1
8+
opcache.enable_cli=1
9+
opcache.file_cache=
10+
opcache.file_cache_only=0
11+
--FILE--
12+
<?php
13+
14+
if (time() > 0) {
15+
function foo($a, $b = null, $c = null) {
16+
var_dump($a, $b, $c);
17+
}
18+
}
19+
20+
try {
21+
2 |> foo(1, unknown: ?);
22+
} catch (Error $e) {
23+
echo $e::class, ": ", $e->getMessage(), "\n";
24+
}
25+
26+
?>
27+
--EXPECTF--
28+
$_main:
29+
; (lines=11, args=0, vars=0, tmps=2)
30+
; (after optimizer)
31+
; %s:1-12
32+
0000 INIT_FCALL 0 %d string("time")
33+
0001 V1 = DO_ICALL
34+
0002 T0 = IS_SMALLER int(0) V1
35+
0003 JMPZ T0 0005
36+
0004 DECLARE_FUNCTION string("foo") 0
37+
0005 INIT_FCALL_BY_NAME 1 string("foo")
38+
0006 SEND_VAL_EX int(1) 1
39+
0007 SEND_VAL_EX int(2) string("unknown")
40+
0008 CHECK_UNDEF_ARGS
41+
0009 DO_FCALL_BY_NAME
42+
0010 RETURN int(1)
43+
44+
foo:
45+
; (lines=9, args=3, vars=3, tmps=0)
46+
; (after optimizer)
47+
; %s:4-6
48+
0000 CV0($a) = RECV 1
49+
0001 CV1($b) = RECV_INIT 2 null
50+
0002 CV2($c) = RECV_INIT 3 null
51+
0003 INIT_FCALL 3 %d string("var_dump")
52+
0004 SEND_VAR CV0($a) 1
53+
0005 SEND_VAR CV1($b) 2
54+
0006 SEND_VAR CV2($c) 3
55+
0007 DO_ICALL
56+
0008 RETURN null
57+
58+
Fatal error: Uncaught Error: Unknown named parameter $unknown in %s:%d
59+
Stack trace:
60+
#0 {main}
61+
thrown in %s on line %d
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
PFA pipe optimization: PFA with skipped optional parameter can be optimized
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.opt_debug_level=0x20000
7+
opcache.enable=1
8+
opcache.enable_cli=1
9+
opcache.file_cache=
10+
opcache.file_cache_only=0
11+
--FILE--
12+
<?php
13+
14+
if (time() > 0) {
15+
function foo($a, $b = null, $c = null) {
16+
var_dump($a, $b, $c);
17+
}
18+
}
19+
20+
3 |> foo(1, c: ?);
21+
22+
?>
23+
--EXPECTF--
24+
$_main:
25+
; (lines=11, args=0, vars=0, tmps=2)
26+
; (after optimizer)
27+
; %s:1-12
28+
0000 INIT_FCALL 0 %d string("time")
29+
0001 V1 = DO_ICALL
30+
0002 T0 = IS_SMALLER int(0) V1
31+
0003 JMPZ T0 0005
32+
0004 DECLARE_FUNCTION string("foo") 0
33+
0005 INIT_FCALL_BY_NAME 1 string("foo")
34+
0006 SEND_VAL_EX int(1) 1
35+
0007 SEND_VAL_EX int(3) string("c")
36+
0008 CHECK_UNDEF_ARGS
37+
0009 DO_FCALL_BY_NAME
38+
0010 RETURN int(1)
39+
40+
foo:
41+
; (lines=9, args=3, vars=3, tmps=0)
42+
; (after optimizer)
43+
; %s:4-6
44+
0000 CV0($a) = RECV 1
45+
0001 CV1($b) = RECV_INIT 2 null
46+
0002 CV2($c) = RECV_INIT 3 null
47+
0003 INIT_FCALL 3 %d string("var_dump")
48+
0004 SEND_VAR CV0($a) 1
49+
0005 SEND_VAR CV1($b) 2
50+
0006 SEND_VAR CV2($c) 3
51+
0007 DO_ICALL
52+
0008 RETURN null
53+
int(1)
54+
NULL
55+
int(3)

0 commit comments

Comments
 (0)