|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64399 ArrayObject works with ArrayObject as input but not ArrayAccess
Submitted: 2013-03-09 09:13 UTC Modified: 2016-02-21 12:34 UTC
From: kotlyar dot maksim at gmail dot com Assigned:
Status: Wont fix Package: SPL related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-03-09 09:13 UTC] kotlyar dot maksim at gmail dot com
This code sample works fine


$input = new \ArrayObject;
$input['whatever'] = 'foo';

$array = new \ArrayObject($input);
// will it return foo? right!

so I expected that it should work same way for objects implemented ArrayAccess 
interface. But it is not true.

Test script:

Expected result:
either YourCustomArrayObject::offsetExists or YourCustomArrayObject::offsetGet is 

It should output 1 or 2 and exit the script

Actual result:
PHP Notice:  Undefined index:  whatever in /home/maksim/test.php on line 57


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-21 12:34 UTC]
-Status: Open +Status: Wont fix -Type: Bug +Type: Feature/Change Request
 [2016-02-21 12:34 UTC]
If you pass an object to ArrayObject (and it is not an ArrayObject or ArrayIterator itself), ArrayObject will work on the properties of the object.

We cannot reasonably support ArrayAccess objects, because ArrayObject requires more than this interface to provide its functionality. In particular, it would also need at least Traversable and Countable. However, even with all of these we still couldn't provide complete functionality: The sorting methods essentially require random-access iterators, a concept that doesn't even exist in PHP.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 04:01:27 2023 UTC