#36832 [NEW]: ternery operator parser improvement

From: Date: Thu, 23 Mar 2006 11:59:49 +0000
Subject: #36832 [NEW]: ternery operator parser improvement
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-94809@lists.php.net to get a copy of this message
From: rdoggett at oz dot net Operating system: any PHP version: 5.1.2 PHP Bug Type: Feature/Change Request Bug description: ternery operator parser improvement Description: ------------ The ternery operator causes grief because its parsing precedence is makedly different from other languages, as shown in the attached code. One could reasonably expect the output to be "1 < 2", and indeed this is the case when translated to perl, c, or javascript. It is difficult to believe that php's behavior could be an intentional language feature. The problem can be solved by inserting nested parenthesis, so the parser's notion of operator precedence is implicated. Although changing it to work more like other languages *could* break some existing php code, this seems very unlikely. It could actually fix some unfound bugs. Please, if you don't change the implementation, at least make the manual explain how the ternery operator's parsing precedence works. (with a big warning) Reproduce code: --------------- <? $p = 1; $out = ($p < 2) ? '< 2' : ($p > 4) ? '> 4' : '= $p'; echo "$p $out\n"; ?> Expected result: ---------------- 1 < 2 Actual result: -------------- 1 > 4 -- Edit bug report at http://bugs.php.net/?id=36832&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36832&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36832&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36832&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36832&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36832&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36832&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36832&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36832&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36832&r=support Expected behavior: http://bugs.php.net/fix.php?id=36832&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36832&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36832&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36832&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36832&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36832&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36832&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36832&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36832&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36832&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36832&r=mysqlcfg

« previous php.bugs (#94809) next »