|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78779 Null Coalescing Operator: Trying to access array offset on value of type null
Submitted: 2019-11-04 12:31 UTC Modified: 2019-12-04 09:31 UTC
From: bugreport2 at gmail dot com Assigned:
Status: Feedback Package: Scripting Engine problem
PHP Version: 7.4Git-2019-11-04 (Git) OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-11-04 12:31 UTC] bugreport2 at gmail dot com
"Trying to access array offset on value of type null" is new and fully dserved but in context of "Null Coalescing Operator" it makes no sense

no matter if $arr or $arr[0] is undefined, the left side is NULL and so assign '' and you are done - probably even potential for optimization

$arr = mysqli_fetch_row($result);
$oldcontent = $arr[0] ?? '';

AUTOTEST ERROR-HANDLER: 'code: 8' 'msg: Trying to access array offset on value of type null' 'file: misc.php' 'line: 116'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-05 11:20 UTC]
-Status: Open +Status: Feedback
 [2019-11-05 11:20 UTC]
I can't reproduce this:
 [2019-11-05 11:39 UTC] bugreport2 at gmail dot com
it was triggered by a fuzzy-testsuite on two out of millions of calls :-(

i replaced the offending code path with a construct used all over the codebase which should silence it as intended 

i find it interesting that it's even possible that this warning triggers at all when "Null Coalescing Operator" is used because there is no point to look at the array offset when the whole $arr is NULL

-  $arr = mysqli_fetch_row($db->query($sql));
-  $oldcontent = $arr[0] ?? '';
+  $oldcontent = (string)(mysqli_fetch_row($db->query($sql))[0] ?? '');
 [2019-11-17 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2019-11-17 11:41 UTC]
-Status: No Feedback +Status: Open
 [2019-11-17 11:41 UTC]
Opening, since feedback had been provided.
 [2019-12-04 09:31 UTC]
-Status: Open +Status: Feedback
 [2019-12-04 09:31 UTC]
Unless there's some working reproduction code for this, I don't think we can do anything here.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 12:01:23 2019 UTC