From:             qjahe at videotron dot ca
Operating system: Linux Debian...
PHP version:      5.0.3
PHP Bug Type:     Arrays related
Bug description:  offsetGet() return E_NOTICE on multidimension arrays

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

-- 
Edit bug report at http://bugs.php.net/?id=33478&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33478&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33478&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33478&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33478&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33478&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33478&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33478&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33478&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33478&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33478&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33478&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33478&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33478&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33478&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33478&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33478&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33478&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33478&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33478&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33478&r=mysqlcfg

Reply via email to