php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78017 Null coalesce operator in if paranthesis causes unexpected behaviour
Submitted: 2019-05-15 13:26 UTC Modified: 2019-05-15 13:37 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dorndorf at featdd dot de Assigned:
Status: Not a bug Package: PHP Language Specification
PHP Version: 7.2.18 OS: macOS 10.14.4
Private report: No CVE-ID: None
 [2019-05-15 13:26 UTC] dorndorf at featdd dot de
Description:
------------
Using the null coalesce operator inside an if paranthesis using and resulting in false will match the condition anyway when the returned value is true.

Test script:
---------------
if (true ?? false && 0 > 0) {
    echo 'Should not be true';
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-15 13:37 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2019-05-15 13:37 UTC] nikic@php.net
?? has lower precedence than &&, so this is true ?? (false && 0 > 0). See https://www.php.net/manual/en/language.operators.precedence.php for operator precedence in PHP.
 [2019-05-15 14:58 UTC] dorndorf at featdd dot de
oh my shame, I had a more complex example in my project where this case can easily be misunderstood.

Thanks for the quick response, learned something interesting new today :-)
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 20 02:03:37 2021 UTC