Bug #81212 [Opn->Nab]: Throws a Notice exception when the [Null Coalescing Operator] detects an array

From: Date: Thu, 01 Jul 2021 07:07:48 +0000
Subject: Bug #81212 [Opn->Nab]: Throws a Notice exception when the [Null Coalescing Operator] detects an array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234716@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81212&edit=1

 ID:                 81212
 Updated by:         nikic@php.net
 Reported by:        su at zorzz dot com
 Summary:            Throws a Notice exception when the [Null Coalescing
                     Operator] detects an array
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   linux(CentOS7.2)
 PHP Version:        7.3.28
 Block user comment: N
 Private report:     N

 New Comment:

Null coalesce is not a generic error suppression operator. The only error conditions it needs to
suppress are "undefined index" style errors. For historical reasons, some additional
errors may be suppressed, but that's generally something we're moving away from.


Previous Comments:
------------------------------------------------------------------------
[2021-07-01 06:22:14] su at zorzz dot com

Description:
------------
Null Coalescing Operator throw a notice when key is a numeric string, just like "10-10" or
"123b".

Test script:
---------------
<?php
error_reporting(E_ALL);
date_default_timezone_set("Asia/Shanghai");

$context = ['attributes' => 'config'];

// example1
var_dump($context['attributes']['10-10'][':type'] ?? null);

// the same as example1
var_dump(isset($context['attributes']['10-10'][':type']) ?
$context['attributes']['10-10'][':type'] : null);


Expected result:
----------------
NULL

NULL

// Isset function and [Null Coalescing Operator] should not throw exceptions.

Actual result:
--------------
Notice: A non well formed numeric value encountered in /home/zorzz/index.php on line 8
NULL

Notice: A non well formed numeric value encountered in /home/zorzz/index.php on line 9
NULL


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81212&edit=1


Thread (5 messages)

« previous php.bugs (#234716) next »