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 {
11
11
return $ a * 2 ;
12
12
}
13
13
14
- $ bad_func = null ;
15
-
16
- $ res1 = 5 |> $ bad_func ? ' _test1 ' : ' _test2 ' ;
14
+ function _test3 ( int $ a ): int {
15
+ return $ a * 100 ;
16
+ }
17
17
18
+ // $config is null, so the second function gets used.
19
+ $ config = null ;
20
+ $ res1 = 5 |> $ config ? _test1 (...) : _test2 (...);
18
21
var_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
+
19
38
?>
20
39
--EXPECT--
21
40
int(10)
41
+ int(6)
42
+ int(4)
You can’t perform that action at this time.
0 commit comments