Bug #79393 [NEW]: Null coalescing operator failing with SplFixedArray

From: Date: Wed, 18 Mar 2020 12:59:31 +0000
Subject: Bug #79393 [NEW]: Null coalescing operator failing with SplFixedArray
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226151@lists.php.net to get a copy of this message
From: julien dot falque at gmail dot com Operating system: Linux PHP version: 7.4.4RC1 Package: SPL related Bug Type: Bug Bug description:Null coalescing operator failing with SplFixedArray 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 bug report at https://bugs.php.net/bug.php?id=79393&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79393&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79393&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79393&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79393&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79393&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79393&r=support Expected behavior: https://bugs.php.net/fix.php?id=79393&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79393&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79393&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79393&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79393&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79393&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79393&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79393&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79393&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79393&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79393&r=mysqlcfg

« previous php.bugs (#226151) next »