From:             matschek at gmx dot de
Operating system: Win32, Linux
PHP version:      4.3.2
PHP Bug Type:     Documentation problem
Bug description:  ?: (ternary) - shold operate as in C, but does not

Description:
------------
The documentation says in the section Comparison Operators:

"Another conditional operator is the "?:" (or ternary) operator, which
operates as in C and many other languages"

This is not true, because in C and other languages the ternary-operator is
parsed/compiled from left to right, and therefore cases other results.

The included code returns "1" in C and JavaScript, for example, but "2" in
PHP

Reproduce code:
---------------
$c1=true;
$c2=false;

echo $c1 ? 1 : $c2 ? 2 : 3;


Expected result:
----------------
1

Actual result:
--------------
2

-- 
Edit bug report at http://bugs.php.net/?id=25356&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25356&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25356&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25356&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25356&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25356&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25356&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25356&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25356&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25356&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25356&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25356&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25356&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25356&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25356&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25356&r=gnused

Reply via email to