|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79393 Null coalescing operator failing with SplFixedArray
Submitted: 2020-03-18 12:59 UTC Modified: 2020-03-18 15:16 UTC
From: julien dot falque at gmail dot com Assigned: cmb (profile)
Status: Closed Package: SPL related
PHP Version: 7.4.4RC1 OS: Linux
Private report: No CVE-ID: None
 [2020-03-18 12:59 UTC] julien dot falque at gmail dot com
This is probably related to

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():
 * with null coalescing operator:

For some reason, using a class that extends SplFixedArray and overrides method offsetExists() works:

Test script:

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

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


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-18 15:16 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2020-03-18 15:16 UTC]
The following pull request has been associated:

Patch Name: Fix #79393: Null coalescing operator failing with SplFixedArray
On GitHub:
 [2020-03-23 13:06 UTC]
Automatic comment on behalf of
Log: Fix #79393: Null coalescing operator failing with SplFixedArray
 [2020-03-23 13:06 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 03:01:28 2024 UTC