Bug #78568 [Opn->Nab]: Incorrect evaluation of ?? and ? containing expression

From: Date: Thu, 19 Sep 2019 16:34:52 +0000
Subject: Bug #78568 [Opn->Nab]: Incorrect evaluation of ?? and ? containing expression
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222831@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78568&edit=1 ID: 78568 Updated by: requinix@php.net Reported by: carlos at wfmh dot org dot pl Summary: Incorrect evaluation of ?? and ? containing expression -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: Linux PHP Version: 7.3.9 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php https://www.php.net/manual/en/language.operators.precedence.php ?? has higher precedence than ?: Previous Comments: ------------------------------------------------------------------------ [2019-09-19 16:30:36] carlos at wfmh dot org dot pl Description: ------------ Incorrect evaluation of ?? and ? containing expression. This code produces incorrect results: <?php $result = 20; $success = false; $result = $result ?? $success ? "TRUE" : "FALSE"; var_dump($result); would output "TRUE" instead of expected 20. Workaround is to put ternary into brackets: <?php $result = 20; $success = false; $result = $result ?? ($success ? "TRUE" : "FALSE"); var_dump($result); and then the result is as expected 20. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78568&edit=1

« previous php.bugs (#222831) next »