Bug #70021 [NEW]: incorrect associativity of ternary operator
From: mega at ioexception dot at
Operating system:
PHP version: 7.0Git-2015-07-08 (Git)
Package: Scripting Engine problem
Bug Type: Bug
Bug description:incorrect associativity of ternary operator
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. [see also bug 61915]
Due to the massive amount of changes in PHP 7, some of which break
backwards compatibility, it would be a great idea to fix this long
standing issue. Although it has been pointed out before that this
behavior is documented it's a non-sane and unconventional result. In
other languages that implement the ternary operator the result of the
test script is 'Swiss Cheese'. This result is expected and
conventional.
This issue has been pointed out multiple times before (61915, 25356).
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:
----------------
Toast
Actual result:
--------------
Swiss Cheese
--
Edit bug report at https://bugs.php.net/bug.php?id=70021&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70021&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70021&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70021&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70021&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70021&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70021&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70021&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70021&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70021&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70021&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70021&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70021&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70021&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70021&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70021&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70021&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70021&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70021&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70021&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70021&r=mysqlcfg
Thread (5 messages)
- mega at ioexception dot at