ID: 48489
Updated by: [email protected]
Reported By: angafenion at yahoo dot com
-Status: Open
+Status: Bogus
Bug Type: SPL related
Operating System: win32
PHP Version: 5.3.0RC2
New Comment:
This is expected, the statement:
$foo->baz['bar'] = 'far';
tries to affect the variable $foo->baz, and hence need to get it
first.
This is why offsetGet is called.
ArrayObject::offsetGet() uses various hacks to return a reference to
the initial array, allowing modifications.
Previous Comments:
------------------------------------------------------------------------
[2009-06-07 08:40:52] angafenion at yahoo dot com
Description:
------------
I overrode the methods of ArrayObject to normalize the keys before
setting and getting members. It appears that the overridden methods are
skipped when modifying an array member.
Reproduce code:
---------------
<?php
class foo extends ArrayObject
{
public function __construct($data = array(),
$flags = self::ARRAY_AS_PROPS,
$iterator = "ArrayIterator")
{
parent::__construct($data, $flags, $iterator);
}
public function offsetSet($key, $val)
{
echo "offsetSet invoked\n";
parent::offsetSet($key, $val);
}
public function offsetGet($key)
{
echo "offsetGet invoked\n";
return parent::offsetGet($key);
}
}
$foo = new foo();
$foo->baz = array();
echo count($foo->baz) . "\n";
echo "---\n";
$foo->baz['bar'] = 'foo';
echo count($foo->baz) . "\n";
Expected result:
----------------
offsetSet invoked
offsetGet invoked
0
---
offsetGet invoked --[*]
offsetSet invoked _/
offsetGet invoked
1
[*] actually, I'm not sure exactly what output to expect here, but at
least one of these I think should appear
Actual result:
--------------
offsetSet invoked
offsetGet invoked
0
---
offsetGet invoked
1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48489&edit=1