|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81212 Throws a Notice exception when the [Null Coalescing Operator] detects an array
Submitted: 2021-07-01 06:22 UTC Modified: 2021-07-01 07:55 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: su at zorzz dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.3.28 OS: linux(CentOS7.2)
Private report: No CVE-ID: None
 [2021-07-01 06:22 UTC] su at zorzz dot com
Null Coalescing Operator throw a notice when key is a numeric string, just like "10-10" or "123b".

Test script:

$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:


// 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

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-01 07:07 UTC]
-Status: Open +Status: Not a bug
 [2021-07-01 07:07 UTC]
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.
 [2021-07-01 07:20 UTC] su at zorzz dot com
But the PHP manual gives a similar use, and "10-10" is a correct index.
I'm amazed. I think the judgment behavior is inconsistent in some cases.
 [2021-07-01 07:26 UTC]
?? will not hide trying to use an invalid *string offset*. Because $context['attributes'] is a string, not an array.

$array['10-10'] ?? null is okay.
$string['10-10'] ?? null is not okay.
 [2021-07-01 07:55 UTC] su at zorzz dot com
I got it.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 00:01:32 2024 UTC