Skip to content

Commit ec75335

Browse files
committed
Expand ternary test.
1 parent 37d75e2 commit ec75335

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

Zend/tests/pipe_operator/precedence_ternary.phpt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff 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(...);
1821
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+
1938
?>
2039
--EXPECT--
2140
int(10)
41+
int(6)
42+
int(4)

0 commit comments

Comments
 (0)