Skip to content

left-associative ternary operator  #8489

Open
@azjezz

Description

@azjezz

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 :


HHVM Version

framework git:(http) ✗ hhvm --version
HipHop VM 4.1.0 (rel)
Compiler: 1555455032_861766839
Repo schema: b1f582ab39dca7cf649292454f7b664970bf83d9framework git:(http) ✗ hh_client --version
hh-21577913b41b950cbe2cd887f46cb30964e59cbd-4.1.0 Tue Apr 16 23:55:04 2019framework 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions