Open
Description
Hack seems to follow PHP in this unusual behavior, but since PHP 5.x support is gone, its time to fix this.
Similar to what @[nikic] proposed for PHP 7.4, the type checker HHVM can force using parentheses with nested ternary operations, and a change can be made in the future to make the ternary operation right-associative.
links :
- https://bugs.php.net/bug.php?id=61915
- https://externals.io/message/105163
- https://wiki.php.net/rfc/ternary_associativity
HHVM Version
➜ framework git:(http) ✗ hhvm --version
HipHop VM 4.1.0 (rel)
Compiler: 1555455032_861766839
Repo schema: b1f582ab39dca7cf649292454f7b664970bf83d9
➜ framework git:(http) ✗ hh_client --version
hh-21577913b41b950cbe2cd887f46cb30964e59cbd-4.1.0 Tue Apr 16 23:55:04 2019
➜ framework git:(http) ✗
Operating System and Version
irrelevant
Standalone code, or other way to reproduce the problem
<<__EntryPoint>>
function main(): void {
$order = "3";
$food = ($order == '1') ? 'Banana' :
($order == '2') ? 'Apple' :
($order == '3') ? 'Toast' :
($order == '4') ? 'Cantalope' :
($order == '5') ? 'Swiss Cheese' : 'Fig Newton Cookie';
print $food . "\n";
}
Actual result
Swiss Cheese
Expected result
Toast