php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80204 Warning if index not exists on reference
Submitted: 2020-10-08 12:41 UTC Modified: 2020-11-01 09:28 UTC
From: rico dot unbehaun at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 8.0.0rc1 OS: Ubuntu 18.04.4 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rico dot unbehaun at gmail dot com
New email:
PHP Version: OS:

 

 [2020-10-08 12:41 UTC] 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 ...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-08 12:51 UTC] sjon@php.net
-Status: Open +Status: Feedback
 [2020-10-08 12:51 UTC] 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-09 11:04 UTC] rico dot unbehaun at gmail dot com
-Status: Feedback +Status: Open
 [2020-10-09 11:04 UTC] 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-12 11:09 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2020-10-12 11:09 UTC] nikic@php.net
The behavior here is the same in beta4 and rc1. Does the issue really reproduce with exactly this code?
 [2020-10-25 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2020-11-01 07:22 UTC] rico dot unbehaun at gmail dot com
-Status: No Feedback +Status: Closed
 [2020-11-01 07:22 UTC] rico dot unbehaun at gmail dot com
Sorry for the late answer. We have found that the error is thrown at another place after all. This was not immediately obvious.
 [2020-11-01 09:28 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 02:03:41 2022 UTC