Bug #79970 [Nab]: Null coalescing operator needs to have a higher precedence value

From: Date: Thu, 13 Aug 2020 13:35:42 +0000
Subject: Bug #79970 [Nab]: Null coalescing operator needs to have a higher precedence value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228578@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79970&edit=1 ID: 79970 User updated by: folarin at engineer dot com Reported by: folarin at engineer dot com Summary: Null coalescing operator needs to have a higher precedence value Status: Not a bug Type: Bug Package: *Programming Data Structures PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Fair enough Previous Comments: ------------------------------------------------------------------------ [2020-08-13 12:48:06] nikic@php.net Precedence is a trade-off. Use explicit parentheses in cases where it is not clear to you. The current choice of precedence is for consistency with the ?: operator, and consistency across languages (e.g. matches C# operator precedence). ------------------------------------------------------------------------ [2020-08-13 12:47:05] cmb@php.net . ------------------------------------------------------------------------ [2020-08-13 12:46:40] cmb@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. > why do I have to do the above when none of if (!empty($var1) && !empty($var2)) ------------------------------------------------------------------------ [2020-08-13 12:43:42] folarin at engineer dot com Description: ------------ Look at the following example $var1 = true $var2 = true if($var1??false && $var2) echo 'Passed" else echo 'Failed' The above expresion always prints 'Failed' which isn't the expected behaviour. Just like the Parenthesis, the null-coalescing operator should ALWAYS be expressed first. This now causes the unwanted, over-expressive use of parenthesis to remedy the cause ALL THE TIME: if(($var1??false) && ($var2??false))... why do I have to do the above when none of ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79970&edit=1

« previous php.bugs (#228578) next »