Bug #80204 [Opn->Fbk]: Warning if index not exists on reference

From: Date: Thu, 08 Oct 2020 12:51:26 +0000
Subject: Bug #80204 [Opn->Fbk]: Warning if index not exists on reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229474@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80204&edit=1 ID: 80204 Updated by: sjon@php.net Reported by: rico dot unbehaun at gmail dot com Summary: Warning if index not exists on reference -Status: Open +Status: Feedback Type: Bug Package: *General Issues Operating System: Ubuntu 18.04.4 LTS PHP Version: 8.0.0rc1 Block user comment: N Private report: N New Comment: Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. This seems to work just fine? See https://3v4l.org/IoOuH Previous Comments: ------------------------------------------------------------------------ [2020-10-08 12:41:13] rico dot unbehaun at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=80204&edit=1

« previous php.bugs (#229474) next »