#30825 [Fbk->Opn]: Ternary operator (?:) goes wrong
| From: | Arne dot Heizmann at csr dot com | Date: | Thu, 18 Nov 2004 15:05:50 +0000 |
| Subject: | #30825 [Fbk->Opn]: Ternary operator (?:) goes wrong | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-69215@lists.php.net to get a copy of this message | ||
ID: 30825
User updated by: Arne dot Heizmann at csr dot com
Reported By: Arne dot Heizmann at csr dot com
-Status: Feedback
+Status: Open
Bug Type: Unknown/Other Function
Operating System: Windows XP
PHP Version: 4.3.9
New Comment:
I understand now that the test case outputs "No" because it interprets
the code as:
echo (true ? "Yes" :
false) ? "No" : "No2";
but clearly this is not useful; I think the precedence of the operator
should be changed so that programmers won't have to insert extra
parentheses to disambiguate the construct.
Previous Comments:
------------------------------------------------------------------------
[2004-11-18 16:03:32] tony2001@php.net
Could tell me how do you think it should work:
like this
echo (true ? "Yes" : false) ? "No" : "No2";
or like this
echo true ? "Yes" : (false ? "No" : "No2");
and why ?
------------------------------------------------------------------------
[2004-11-18 15:40:59] Arne dot Heizmann at csr dot com
Description:
------------
The ternary conditional operator (?:) goes wrong when nested two levels
deep.
When adding parentheses, the bug disappears, even when the parentheses
are redundant and shouldn't make any difference.
Reproduce code:
---------------
echo true ? "Yes" :
false ? "No" : "No2";
Expected result:
----------------
"Yes"
Actual result:
--------------
"No"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30825&edit=1