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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dorndorf at featdd dot de
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC