Bug #79393 [Opn->Ver]: Null coalescing operator failing with SplFixedArray
| From: | cmb@php.net | Date: | Wed, 18 Mar 2020 15:16:17 +0000 |
| Subject: | Bug #79393 [Opn->Ver]: Null coalescing operator failing with SplFixedArray | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226165@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79393&edit=1
ID: 79393
Updated by: cmb@php.net
Reported by: julien dot falque at gmail dot com
Summary: Null coalescing operator failing with SplFixedArray
-Status: Open
+Status: Verified
Type: Bug
Package: SPL related
Operating System: Linux
PHP Version: 7.4.4RC1
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2020-03-18 12:59:31] julien dot falque at gmail dot com
Description:
------------
This is probably related to https://bugs.php.net/bug.php?id=74478.
Using null coalescing operation on an index that does not exist in an SplFixedArray triggers an
exception (Index invalid or out of range) while doing the same with isset() works as expected.
See the following snippets:
* with isset(): https://3v4l.org/s79uA
* with null coalescing operator: https://3v4l.org/ucSbZ
For some reason, using a class that extends SplFixedArray and overrides method offsetExists() works:
https://3v4l.org/5ohF1.
Test script:
---------------
<?php
$foo = new SplFixedArray(2);
$foo[0] = 'bar1';
$foo[1] = 'bar2';
var_dump($foo[0] ?? null);
var_dump($foo[1] ?? null);
var_dump($foo[2] ?? null);
Expected result:
----------------
string(4) "bar1"
string(4) "bar2"
NULL
Actual result:
--------------
string(4) "bar1"
string(4) "bar2"
Fatal error: Uncaught RuntimeException: Index invalid or out of range in /in/ucSbZ:9
Stack trace:
#0 {main}
thrown in /in/ucSbZ on line 9
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79393&edit=1