|  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
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dorndorf at featdd dot de
New email:
PHP Version: OS:


 [2019-05-15 13:26 UTC] dorndorf at featdd dot de
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';


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-15 13:37 UTC]
-Status: Open +Status: Not a bug
 [2019-05-15 13:37 UTC]
?? has lower precedence than &&, so this is true ?? (false && 0 > 0). See 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-2023 The PHP Group
All rights reserved.
Last updated: Tue Oct 03 01:01:24 2023 UTC