Bug->Req #64399 [Opn->Wfx]: ArrayObject works with ArrayObject as input but not ArrayAccess
| From: | nikic@php.net | Date: | Sun, 21 Feb 2016 12:34:09 +0000 |
| Subject: | Bug->Req #64399 [Opn->Wfx]: ArrayObject works with ArrayObject as input but not ArrayAccess | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199369@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64399&edit=1
ID: 64399
Updated by: nikic@php.net
Reported by: kotlyar dot maksim at gmail dot com
Summary: ArrayObject works with ArrayObject as input but not
ArrayAccess
-Status: Open
+Status: Wont fix
-Type: Bug
+Type: Feature/Change Request
Package: SPL related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-03-09 09:13:33] kotlyar dot maksim at gmail dot com
Description:
------------
This code sample works fine
<?php
$input = new \ArrayObject;
$input['whatever'] = 'foo';
$array = new \ArrayObject($input);
var_dump($array['whatever']);
// 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:
---------------
https://gist.github.com/makasim/5123486
Expected result:
----------------
either YourCustomArrayObject::offsetExists or YourCustomArrayObject::offsetGet is
called
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64399&edit=1