Edit report at https://bugs.php.net/bug.php?id=78779&edit=1
ID: 78779
Comment by: bugreports3 at gmail dot com
Reported by: bugreport2 at gmail dot com
Summary: Null Coalescing Operator: Trying to access array
offset on value of type null
Status: Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.4Git-2019-11-04 (Git)
Block user comment: N
Private report: N
New Comment:
> in previous PHP versions, this code did not throw an error > and the returned value was instead considered as null
but your code is *expected* to throw an error in newer versions while "$arr[0] ??
''" is not, no matter if $arr or $arr[0] is undefined
Previous Comments:
------------------------------------------------------------------------
[2019-12-07 19:16:39] contact at kevin-anidjar dot com
@requinix@php.net: in previous PHP versions, this code did not throw an error and the returned value
was instead considered as null.
------------------------------------------------------------------------
[2019-12-07 19:07:58] requinix@php.net
@kevin-anidjar: That does not reproduce the issue. The code must use ?? immediately after a value
and without that value going through a function.
------------------------------------------------------------------------
[2019-12-07 19:07:35] bugreports3 at gmail dot com
sadly "echo strval($arr['foo']) ?? 'bar';" is a invalid reproducer and
expected to thow a warning becaus ein that line strval() is feeded with $arr['foo'] and
"?? 'bar'" would only be relevant wehn that returns NULL which is not possible
by the nature of strval()
this is a completly different beast
$oldcontent = $arr[0] ?? '';
------------------------------------------------------------------------
[2019-12-07 19:01:14] contact at kevin-anidjar dot com
Hi, here is a way to reproduce the issue:
https://3v4l.org/mX3Pf
------------------------------------------------------------------------
[2019-12-04 09:31:44] nikic@php.net
Unless there's some working reproduction code for this, I don't think we can do anything
here.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=78779
--
Edit this bug report at https://bugs.php.net/bug.php?id=78779&edit=1