php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33169 ArrayAccess doesn't work at all
Submitted: 2005-05-28 10:09 UTC Modified: 2005-05-28 14:31 UTC
From: tomas_matousek at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.4 OS: WinXP
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: tomas_matousek at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-05-28 10:09 UTC] tomas_matousek at hotmail dot com
Description:
------------
I looks like you have never do in-depth testing with ArrayAccess. I you did you must realize many things are wrong there. It took me less then 5 minutes to kill PHP several times using this naively implemented feature.




Reproduce code:
---------------
class ArrayClass implements ArrayAccess {

public $a = array();

function offsetExists($index) {

    return array_key_exists($index, $this->a);

}

function offsetGet($index) {

    return $this->a[$index];

}

function offsetSet($index, $newval) {

    return $this->a[$index] = $newval;

}

function offsetUnset($index) {

    unset($this->a[$index]);

}

}



Expected result:
----------------
It's unclear for me what should I expect.
Definitly not the crashes.

Can anyone explain, what should I expect from e.g.
$obj[1][2][3] = 1; ?

And what should 
$a =& $obj[1][2][3];
do?


Actual result:
--------------
$obj[array()] = 1; // crash
$obj[][] = 1;      // crash
$x =& $obj[1]      // crash
$obj[$obj[1]] = 1; // if offsetGet() returns null, the offsetSet() is called then
$obj[1]++; // doesn't work at all even if both offsetGet and offsetSet are modified to return by reference

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-28 10:20 UTC] tomas_matousek at hotmail dot com
I'm sorry for mystifying with:
$obj[][] = 1;      
it doesn't crash yet reports strange error even if I return an array by reference from offsetGet():
Fatal error:  Objects used as arrays in post/pre increment/decrement must return values by reference in C:\Web\$PhpTests\y.php on line 32.

this also works fine:
$obj[$obj[1]] = 1;

but others don't



$obj[$obj[1]] = 1;
 [2005-05-28 11:46 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Can't reproduce any of these problems with latest CVS (of course, if "Warning: Illegal offset type" is not a mentined "crash").

 [2005-05-28 14:31 UTC] tomas_matousek at hotmail dot com
Sorry for confusing report. I've tested in on 5.0.3 instead of 5.0.4. In the previous version, almost nothing has worked. In 5.0.4. it seems to be ok.
So this is a bogus, sorry for that.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 16:01:36 2024 UTC