#34816 [Asn->Bgs]: Inconsitent behavior in ArrayObject for multi-dimensional data
| From: | helly@php.net | Date: | Mon, 10 Oct 2005 18:23:15 +0000 |
| Subject: | #34816 [Asn->Bgs]: Inconsitent behavior in ArrayObject for multi-dimensional data | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-86360@lists.php.net to get a copy of this message | ||
ID: 34816
Updated by: helly@php.net
Reported By: adove at booyahnetworks dot com
-Status: Assigned
+Status: Bogus
Bug Type: SPL related
Operating System: WinXP
PHP Version: 5.1.0RC1
Assigned To: helly
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
ArrayObject/ArrayIterator simply implement the ArrayAccess imnterface
which doesn't handle multi dimensional array syntax. As you pointer out
already you could have ArrayObject store ArrayObjects itself. Thus the
solution is to overwrite ArrayObject.
Previous Comments:
------------------------------------------------------------------------
[2005-10-10 19:51:36] derick@php.net
marcus, this is your baby :)
------------------------------------------------------------------------
[2005-10-10 19:42:23] adove at booyahnetworks dot com
Description:
------------
If you create an ArrayObject with mutli-dimensional array data, you can
access unique element paths fine but you can not change/add any
multi-dimensional paths due to the dreaded "Fatal error: Objects used
as arrays in post/pre increment/decrement must return values by
reference" error. Note this happens in BOTH 5.0.5 AND 5.1.0RC1.
IMHO, either the documentation for ArrayObject should clearly indicate
that it supports uni-dimenisional data get/set and ONLY get for
multi-dimensional. OR, the object walk the passed data and turn all
arrays into ArrayObject instances?
Reproduce code:
---------------
$a = array(
"test" => array(
"one" => "dunno",
"two" => array(
"peekabo" => "do you see me?",
"anyone" => array("there")
)
)
);
$oArray = new ArrayObject($a);
var_dump($oArray);
echo "\n\\test\\one == " . $oArray["test"]["one"] . "\n\n";
// NEITHER of the two below will work!
$oArray["test"]["one"] = "Yes I do!";
$oArray["test"]["yes"] = array(
"hello" => "Goodbye!"
);
var_dump($oArray);
Expected result:
----------------
object(ArrayObject)#1 (1) {
["test"]=>
array(2) {
["one"]=>
string(5) "dunno"
["two"]=>
array(2) {
["peekabo"]=>
string(14) "do you see me?"
["anyone"]=>
array(1) {
[0]=>
string(5) "there"
}
}
}
}
\test\one == dunno
object(ArrayObject)#1 (1) {
["test"]=>
array(2) {
["one"]=>
string(5) "Yes I do!"
["two"]=>
array(2) {
["peekabo"]=>
string(14) "do you see me?"
["anyone"]=>
array(1) {
[0]=>
string(5) "there"
}
}
["yes"]=>
array(1) {
["hello"]=>
string(8) "Goodbye!"
}
}
}
Actual result:
--------------
object(ArrayObject)#1 (1) {
["test"]=>
array(2) {
["one"]=>
string(5) "dunno"
["two"]=>
array(2) {
["peekabo"]=>
string(14) "do you see me?"
["anyone"]=>
array(1) {
[0]=>
string(5) "there"
}
}
}
}
\test\one == dunno
Fatal error: Objects used as arrays in post/pre increment/decrement
must return values by reference in array_obje_test.php on line 16
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34816&edit=1