php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75777 Shorthand if/else parsing problem
Submitted: 2018-01-08 08:59 UTC Modified: 2018-01-08 09:12 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kongocode at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.27 OS: Windows 10
Private report: No CVE-ID: None
 [2018-01-08 08:59 UTC] kongocode at gmail dot com
Description:
------------
Hello, today I discovered bug (I think) which occurs in parsing shorthand ifs. It happens when we use shorthand if in shorthand if without braces.

Test script:
---------------
<?php

    echo (true ? "a" : (false) ? "b" : "c");

    //Output is: `b` instead of `a`.
    //Java and C# tells it's `a`
?>

Expected result:
----------------
to see letter `a`

Actual result:
--------------
b

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-08 09:12 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-01-08 09:12 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

https://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
 [2018-01-08 09:13 UTC] haseeb dot basil at gmail dot com
It does provide valid output, when 2nd part of the statement is enclosed in brackets:

<?php
echo (true ? "a" : ((false) ? "b" : "c"));
//Output: a
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 02:01:29 2024 UTC