php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50372 Ternary statements are not identical
Submitted: 2009-12-03 12:13 UTC Modified: 2009-12-04 09:19 UTC
From: jakeophobia at gmail dot com Assigned: rquadling (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2009-12-03 12:13 UTC] 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');

...


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-03 12:52 UTC] 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 21:25 UTC] jakeophobia at gmail dot com
Oops, I meant single quotes. Take a look at false vs. 'false'
 [2009-12-04 09:18 UTC] 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-04 09:19 UTC] svn@php.net
Automatic comment from SVN on behalf of rquadling
Revision: http://svn.php.net/viewvc/?view=revision&revision=291695
Log: Make examples consistent. Fix #50372
 [2009-12-04 09:19 UTC] rquadling@php.net
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.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of rquadling
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=1fc5ea1e2828fd8a2cc55442fc49862466b2609d
Log: Make examples consistent. Fix #50372
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 12:00:02 2026 UTC