Bug #79393 [Ver->Csd]: Null coalescing operator failing with SplFixedArray
| From: | cmb@php.net | Date: | Mon, 23 Mar 2020 13:06:06 +0000 |
| Subject: | Bug #79393 [Ver->Csd]: Null coalescing operator failing with SplFixedArray | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226234@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: Verified
+Status: Closed
Type: Bug
Package: SPL related
Operating System: Linux
PHP Version: 7.4.4RC1
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=47c745555c9000706cd4de7fffc6e1c2f18d5521
Log: Fix #79393: Null coalescing operator failing with SplFixedArray
Previous Comments:
------------------------------------------------------------------------
[2020-03-18 15:16:40] cmb@php.net
The following pull request has been associated:
Patch Name: Fix #79393: Null coalescing operator failing with SplFixedArray
On GitHub: https://github.com/php/php-src/pull/5274
Patch: https://github.com/php/php-src/pull/5274.patch
------------------------------------------------------------------------
[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