note 125585 deleted from language.operators.comparison by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 17:35:09 +0000 |
| Subject: | note 125585 deleted from language.operators.comparison by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217864@lists.php.net to get a copy of this message | ||
Note Submitter: itsacon at itsacon dot net
----
Be aware that the null coalesce operator (??) has a lower priority than most other operators, so
parentheses are usually a good idea if the output is used in anything other than an assignment.
<?php
$var = 1;
if ($var ?? 0 == 2) {} // will evaluate to true
if (2 == $undefinedVar ?? 0) {} // will throw an error
if (($var ?? 0) == 2) {} // will evaluate to false
?>
https://www.php.net/manual/en/language.operators.precedence.php