Bug #75209 [Com]: Bug in ??

From: Date: Thu, 14 Sep 2017 15:25:42 +0000
Subject: Bug #75209 [Com]: Bug in ??
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211162@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75209&edit=1 ID: 75209 Comment by: daverandom@php.net Reported by: ynijar at hotmail dot com Summary: Bug in ?? Status: Not a bug Type: Bug Package: *General Issues Operating System: Windows/Linux PHP Version: 7.0.23 Block user comment: N Private report: N New Comment: https://3v4l.org/Ivv6k Previous Comments: ------------------------------------------------------------------------ [2017-09-14 15:23:48] daverandom@php.net 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 This is the expected behaviour for ??, which is specifically the NULL coalesce operator. The shorthand ternary operator ?: gives the behaviour you are expecting. ------------------------------------------------------------------------ [2017-09-14 15:17:48] ynijar at hotmail dot com Description: ------------ $hash = null; $hash ?? 'test'; // output 'test' $hash = ''; $hash ?? 'test'; // output '' - WHY???? $hash = ""; !$hash ? 'test' : $hash; // output 'test' Test script: --------------- $hash = null; $hash ?? 'test'; // output 'test' $hash = ''; $hash ?? 'test'; // output '' - WHY???? $hash = ""; !$hash ? 'test' : $hash; // output 'test' Expected result: ---------------- $hash = null; $hash ?? 'test'; // output 'test' $hash = ''; $hash ?? 'test'; // output 'test' - it's normal $hash = ""; !$hash ? 'test' : $hash; // output 'test' ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75209&edit=1

« previous php.bugs (#211162) next »