php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: qjahe at videotron dot ca
New email:
PHP Version: OS:

 

 [2005-06-26 04:29 UTC] qjahe at videotron dot ca
Description:
------------
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:
---------------
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL);
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:
----------------
test5

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-26 10:56 UTC] helly@php.net
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: Wed Dec 04 06:01:31 2024 UTC