#50372 [Bgs->Asn]: Ternary statements are not identical

From: Date: Fri, 04 Dec 2009 09:19:28 +0000
Subject: #50372 [Bgs->Asn]: Ternary statements are not identical
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3403@lists.php.net to get a copy of this message
ID: 50372 Updated by: rquadling@php.net Reported By: jakeophobia at gmail dot com -Status: Bogus +Status: Assigned Bug Type: Documentation problem PHP Version: Irrelevant -Assigned To: +Assigned To: rquadling Previous Comments: ------------------------------------------------------------------------ [2009-12-04 09:18:41] rquadling@php.net Aha! I see. Actually, false / 'false' could be anything. echo (true?'true':99?'t':'f'); echo (true?'true':foo?'t':'f'); echo (true?'true':null?'t':'f'); echo (true?'true':false?'t':'f'); echo (true?'true':'false'?'t':'f'); all output 't' as the result do to the left-to-right evaluation. ------------------------------------------------------------------------ [2009-12-03 21:25:25] jakeophobia at gmail dot com Oops, I meant single quotes. Take a look at false vs. 'false' ------------------------------------------------------------------------ [2009-12-03 12:52:42] rquadling@php.net The () in the second version are redundant and are only there to emphasize the left-to-right expression evaluation. The output of both versions is the same, 't'. ------------------------------------------------------------------------ [2009-12-03 12:13:15] jakeophobia at gmail dot com Description: ------------ On page: http://www.php.net/manual/en/language.operators.comparison.php In 'Example #3 Non-obvious Ternary Behaviour' The two statements are not 'identical'. The second ternary statment has parenthesis on 'false' Expected result: ---------------- ... echo (true?'true':false?'t':'f'); ...the following is a more obvious version of the same code as above... echo ((true ? 'true' : false) ? 't' : 'f'); ... Actual result: -------------- ... echo (true?'true':false?'t':'f'); ...the following is a more obvious version of the same code as above... echo ((true ? 'true' : 'false') ? 't' : 'f'); ... ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50372&edit=1

« previous php.doc.bugs (#3403) next »