Bug #78017 [Com]: Null coalesce operator in if paranthesis causes unexpected behaviour

From: Date: Wed, 15 May 2019 14:58:43 +0000
Subject: Bug #78017 [Com]: Null coalesce operator in if paranthesis causes unexpected behaviour
References: 1  Groups: php.standards 
Request: Send a blank email to standards-+get-1442@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78017&edit=1 ID: 78017 Comment by: dorndorf at featdd dot de Reported by: dorndorf at featdd dot de Summary: Null coalesce operator in if paranthesis causes unexpected behaviour Status: Not a bug Type: Bug Package: PHP Language Specification Operating System: macOS 10.14.4 PHP Version: 7.2.18 Block user comment: N Private report: N New Comment: 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 :-) Previous Comments: ------------------------------------------------------------------------ [2019-05-15 13:37:17] 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 13:26:07] 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'; } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78017&edit=1

« previous php.standards (#1442) next »