Bug #80452 [Com]: Null Coalesce Operator Swallow warning error
Edit report at https://bugs.php.net/bug.php?id=80452&edit=1
ID: 80452
Comment by: rtrtrtrtrt at dfdfdfdf dot dfd
Reported by: cxlblm at gmail dot com
Summary: Null Coalesce Operator Swallow warning error
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: docker/ubuntu
PHP Version: 8.0.0
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> Accessing a scalar as an array before php8 will trigger
> a notice, but in php8 it will trigger a warning!
how does that change the simple fact that the purpose of "Null Coalesce" is either take
the left part if it's defined or take the right part?
NOTICE versus WARNING is only relevant for error_reporting
Previous Comments:
------------------------------------------------------------------------
[2020-12-01 11:55:00] cxlblm at gmail dot com
Sorry, my English not good!
see https://3v4l.org/bX1Q1
According to the description of rfc(https://wiki.php.net/rfc/isset_ternary), Null Coalesce Operator
will only suppress notice message.
Accessing a scalar as an array before php8 will trigger a notice, but in php8 it will trigger a
warning!
------------------------------------------------------------------------
[2020-12-01 11:40:08] cmb@php.net
Yes, that is the whole purpose of the null coalesce operator:
<https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce>.
------------------------------------------------------------------------
[2020-12-01 11:30:51] cxlblm at gmail dot com
Thank you for your prompt response!
https://3v4l.org/lsuFc
If there is no ?? in the sixth line of the code, a warning will be raised, but Null Coalesce
Operator is completely safe and will not raise an E_NOTICE!
------------------------------------------------------------------------
[2020-12-01 11:21:01] cmb@php.net
From looking at <https://3v4l.org/4JIAY>, this
doesn't appear to
be a bug. The warning is raised in line 5, where the null
coalesce operator is not used.
------------------------------------------------------------------------
[2020-12-01 11:14:54] cxlblm at gmail dot com
Description:
------------
RFC Null Coalesce Operator:
This means the $_GET['mykey'] ?? "" is completely safe and will not raise an
E_NOTICE!
Test script:
---------------
$a = false;
var_dump($a['abc'] ?? '');
Expected result:
----------------
Warning: Trying to access array offset on value of type bool in /in/4JIAY
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80452&edit=1
Thread (6 messages)