php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80452 Null Coalesce Operator Swallow warning error
Submitted: 2020-12-01 11:14 UTC Modified: 2020-12-01 12:12 UTC
From: cxlblm at gmail dot com Assigned: cmb (profile)
Status: Closed Package: *General Issues
PHP Version: 8.0.0 OS: docker/ubuntu
Private report: No CVE-ID: None
 [2020-12-01 11:14 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-01 11:21 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-12-01 11:21 UTC] 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:30 UTC] cxlblm at gmail dot com
-Status: Feedback +Status: Assigned
 [2020-12-01 11:30 UTC] 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:40 UTC] cmb@php.net
-Status: Assigned +Status: Not a bug
 [2020-12-01 11:40 UTC] 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:55 UTC] 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:59 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
> 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
 [2020-12-01 12:12 UTC] cmb@php.net
-Status: Not a bug +Status: Re-Opened -Type: Bug +Type: Documentation Problem
 [2020-12-01 12:12 UTC] cmb@php.net
Ah, I see.  The docs need to updated in this regard.
 [2020-12-01 12:20 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=351816
Log: Fix #80452: Null Coalesce Operator Swallow warning error
 [2020-12-01 12:22 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=9c098f1e964f310c423844fafb1f8fb4399e4064
Log: Fix #80452: Null Coalesce Operator Swallow warning error
 [2020-12-01 12:22 UTC] phpdocbot@php.net
-Status: Re-Opened +Status: Closed
 [2020-12-02 00:21 UTC] mumumu@php.net
Automatic comment from SVN on behalf of mumumu
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=351835
Log: Fix #80452: Null Coalesce Operator Swallow warning error
 [2020-12-02 00:25 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=44a4bbe239153ab1340d8d75ef4020327e27deb4
Log: Fix #80452: Null Coalesce Operator Swallow warning error
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=8c0e2b7e99606ed2331f42ee5fe833354c7d5842
Log: Fix #80452: Null Coalesce Operator Swallow warning error
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 23:01:29 2024 UTC