#25356 [Ver->Csd]: ?: (ternary) - shold operate as in C, but does not
| From: | irchtml@php.net | Date: | Thu, 08 Apr 2004 04:26:10 +0000 |
| Subject: | #25356 [Ver->Csd]: ?: (ternary) - shold operate as in C, but does not | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969359972@lists.php.net to get a copy of this message | ||
ID: 25356
Updated by: irchtml@php.net
Reported By: matschek at gmx dot de
-Status: Verified
+Status: Closed
Bug Type: Documentation problem
Operating System: Irrelevant
PHP Version: Irrelevant
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Removed note.
Previous Comments:
------------------------------------------------------------------------
[2003-09-02 08:24:49] sniper@php.net
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.
------------------------------------------------------------------------
[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