|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33478 offsetGet() return E_NOTICE on multidimension arrays
Submitted: 2005-06-26 04:29 UTC Modified: 2005-06-26 10:56 UTC
From: qjahe at videotron dot ca Assigned:
Status: Wont fix Package: Arrays related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-06-26 04:29 UTC] qjahe at videotron dot ca
Object implements ArrayAccess.

First to make multi-dimension arrays i've been told there was a bug and I had to put by reference &offsetGet($offset) for that function. After that my multi-dimension arrays were working.

Secondly it appears to ALWAYS, whatever I tried, to return a E_NOTICE when the second index of the array doesnt exists but the first one do exists. [index3 example]

Thirdly when the second index doesnt exists and you are trying to fetch the third thru the second index and first index exists it seems to be returning the first lettre from the value of the last existing index...[index4 example]

How can I check the second, third, fourth, etc... array index when all I get is $offset as a string or only one parameter...

Reproduce code:
ini_set("display_errors", "On");
class Data{
    public static $myArray = array();
    final function __construct(){}
    final function __destruct(){}
    final function __clone(){}
class test implements ArrayAccess{
    function offsetExists($index){
        if (isset(Data::$myArray[$index]))
            return TRUE;
        return FALSE;
    function &offsetGet($index){
        if (isset(Data::$myArray[$index]))
            return Data::$myArray[$index];
        $index = FALSE;
        return $index;
    function offsetSet($index, $value){
        Data::$myArray[$index] = $value;
    function offsetUnset($index){
        Data::$myArray[$index] = NULL;
$test = new test();
$test['index1'] = array();
$test['index1']['test1'] = 'test2';
$test['index1']['index2'] = 'xest3';
$test['test4'] = 'test5';

echo $test['test4'];
echo $test['index1']['index3'];
echo $test['index1']['index2']['index4'];
echo $test['index5'];


Expected result:

Actual result:
Notice: Undefined index: index3 in /path/file.php on line 36


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-26 10:56 UTC]
Starting with PHP 5.1 we ensure correct signatures that is you are no longer able to use have offsetGet return by reference.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 11:01:29 2024 UTC