Bug #80204 [NEW]: Warning if index not exists on reference

From: Date: Thu, 08 Oct 2020 12:41:13 +0000
Subject: Bug #80204 [NEW]: Warning if index not exists on reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229473@lists.php.net to get a copy of this message
From: rico dot unbehaun at gmail dot com Operating system: Ubuntu 18.04.4 LTS PHP version: 8.0.0rc1 Package: *General Issues Bug Type: Bug Bug description:Warning if index not exists on reference Description: ------------ If you pass a variable or an array to a function by reference and check in the function whether the variable or the index exists, you get the following error message: Trying to access array offset on value of type ... This worked fine until PHP 7.4.x. See example Test script: --------------- On PHP 7.4.x the following works fine: define('VOID', INF); function ifsetter(&$mElement, $mDefault = '') { if (!isset($mElement) OR $mElement === VOID){ $mElement = $mDefault; } return $mElement; } $t = []; echo ifsetter($t['aaa'], 'hello'); // return 'hello' and set $t['aaa'] = 'hello'; On PHP 8 I get the warning: Trying to access array offset on value of type ... -- Edit bug report at https://bugs.php.net/bug.php?id=80204&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80204&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80204&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80204&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80204&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80204&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80204&r=support Expected behavior: https://bugs.php.net/fix.php?id=80204&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80204&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80204&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80204&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80204&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80204&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80204&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80204&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80204&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80204&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80204&r=mysqlcfg

« previous php.bugs (#229473) next »