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

From: Date: Mon, 12 Oct 2020 11:09:54 +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-229560@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: nikic@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: The behavior here is the same in beta4 and rc1. Does the issue really reproduce with exactly this code? Previous Comments: ------------------------------------------------------------------------ [2020-10-09 11:04:00] rico dot unbehaun at gmail dot com Thanks for the quick response. Your example is correct. I saw that for some reason we installed PHP 8.0.0beta4. The hoster is currently switching to RC1. I will test it again once we have switched to RC1. ------------------------------------------------------------------------ [2020-10-08 12:51:26] sjon@php.net 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 ------------------------------------------------------------------------ [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 (#229560) next »