File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -11,11 +11,32 @@ function _test2(int $a): int {
1111 return $ a * 2 ;
1212}
1313
14- $ bad_func = null ;
15-
16- $ res1 = 5 |> $ bad_func ? ' _test1 ' : ' _test2 ' ;
14+ function _test3 ( int $ a ): int {
15+ return $ a * 100 ;
16+ }
1717
18+ // $config is null, so the second function gets used.
19+ $ config = null ;
20+ $ res1 = 5 |> $ config ? _test1 (...) : _test2 (...);
1821var_dump ($ res1 );
22+
23+ // $config is truthy, so the ternary binds first
24+ // and evaluates to the first function.
25+ $ config = _test3 (...);
26+ $ res2 = 5 |> $ config ? _test1 (...) : _test2 (...);
27+ var_dump ($ res2 );
28+
29+ // Binding the ternary first doesn't make logical sense,
30+ // so the pipe runs first in this case.
31+ $ x = true ;
32+ $ y = 'beep ' ;
33+ $ z = 'default ' ;
34+ $ ret3 = $ x ? $ y |> strlen (...) : $ z ;
35+ var_dump ($ ret3 );
36+
37+
1938?>
2039--EXPECT--
2140int(10)
41+ int(6)
42+ int(4)
You can’t perform that action at this time.
0 commit comments