ID: 25356 Updated by: [EMAIL PROTECTED] Reported By: matschek at gmx dot de -Status: Open +Status: Verified Bug Type: Documentation problem Operating System: Irrelevant PHP Version: Irrelevant New Comment:
To get the correct result do this: echo $c1 ? 1 : ($c2 ? 2 : 3); Isn't that much readable too? :) Anyway, that note about ternary being same as in C is wrong. Previous Comments: ------------------------------------------------------------------------ [2003-09-02 06:30:51] matschek at gmx dot de 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 this bug report at http://bugs.php.net/?id=25356&edit=1
