Bug #79053 [Com]: No error is reported when using null coalescing operator
| From: | bugreports at gmail dot com | Date: | Wed, 01 Jan 2020 13:48:20 +0000 |
| Subject: | Bug #79053 [Com]: No error is reported when using null coalescing operator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224649@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79053&edit=1
ID: 79053
Comment by: bugreports at gmail dot com
Reported by: rubencm at gmail dot com
Summary: No error is reported when using null coalescing
operator
Status: Open
Type: Bug
Package: *General Issues
PHP Version: 7.4.1
Block user comment: N
Private report: N
New Comment:
<?php
function bar()
{
return false[''];
}
?>
this has again *nothing* to do with "null coalescing operator" because you are not using
it at all, that way you would usie it
<?php
function bar()
{
return false[''] ?? NULL;
}
that all looks like lack of understand php basics
?>
Previous Comments:
------------------------------------------------------------------------
[2020-01-01 13:44:38] bugreports at gmail dot com
you can't seriously compare that becaus ethe case is completly wrong
trigger_error("foo", E_USER_NOTICE); has nothing to do with "null coalescing
operator" at all, you call the function and the function does what it is supposed to do, throw
a E_USER_NOTICE
why do you think "null coalescing operator" is involved here at all?
teh function returns NULL and "bar()??false" does what it is supposed to do
------------------------------------------------------------------------
[2020-01-01 13:41:32] rubencm at gmail dot com
Here is an equivalent codes with diferent behavior
<?php
function bar()
{
return false[''];
}
var_dump(bar()??false);
?>
<?php
var_dump(false['']??false);
?>
------------------------------------------------------------------------
[2020-01-01 13:37:42] rubencm at gmail dot com
Well, in this case the notice is being reported, that still don't have much sense for me.
<?php
function bar()
{
trigger_error("foo", E_USER_NOTICE);
return null;
}
var_dump(bar()??false);
------------------------------------------------------------------------
[2020-01-01 13:28:45] bugreports at gmail dot com
taht's the whole point of null coalescing operator
------------------------------------------------------------------------
[2020-01-01 13:27:09] rubencm at gmail dot com
Description:
------------
When I try to access to an array offset on a boolean, a notice (a warning in master) is thrown.
<?php
false['']; // php notice: "Trying to access array offset on value of type bool"
?>
But when I use the null coalescing operator with it, that error isn't reported
<?php
false['']??false; // false, no error
?>
I'm not sure, but I think it's not the expected behavior, since possible errors are
hidden.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79053&edit=1