Edit report at https://bugs.php.net/bug.php?id=61915&edit=1
ID: 61915 Updated by: johan...@php.net Reported by: iam4webwork at hotmail dot com Summary: incorrect associativity of ternary operator -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Linux,Windows PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Yes, this was an oversight when the language was defined and is documentedlike that on http://php.net/ternary (see the last note). Unfortunately we can't fix this without breaking code, which depends on the current order, in a non-obvious way. Previous Comments: ------------------------------------------------------------------------ [2012-05-02 22:16:24] iam4webwork at hotmail dot com Description: ------------ zend_language_parser.y on line 81 gives the '?:' operator left associativity when it should be right as in virtually every other language that has a ternary operator. Test script: --------------- $arg = "3"; $food = ( ($arg == '1') ? 'Banana' : ($arg == '2') ? 'Apple' : ($arg == '3') ? 'Toast' : ($arg == '4') ? 'Cantalope' : ($arg == '5') ? 'Swiss Cheese' : 'Fig Newton Cookie' ); echo $food; Expected result: ---------------- I expected to see 'Toast'. Actual result: -------------- The actual result is 'Swiss Cheese'. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61915&edit=1