note 57663 added to ref.spl
| From: | adove at booyahnetworks dot com | Date: | Mon, 10 Oct 2005 17:45:37 +0000 |
| Subject: | note 57663 added to ref.spl | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96791@lists.php.net to get a copy of this message | ||
Something to note that, at least to me, seems pretty important and is not entirely clear in the
documentation is the fact that the ArrayObject class supports get/set on uni-dimensional keys and
get ONLY on *passed* multi-dimensional keys/paths (see source below). If you, like me, need to
support array accesss overloading for multi-dimensional data, you will need to derive from
ArrayObject and overide the ArrayAccess interface methods to "walk" passed data and
convert embedded arrays to objects of some kind...
Reference Bug 34816 @ http://bugs.php.net/bug.php?id=34816.
Illustration of the issue:
$a = array(
"test" => array(
"one" => "dunno",
"two" => array(
"peekabo" => "do you see me?",
"anyone" => array("there")
)
)
);
$oArray = new ArrayObject($a);
var_dump($oArray);
$oArray["three"] = "No problems here.";
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);
----
Manual Page -- http://www.php.net/manual/en/ref.spl.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57663
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57663&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57663&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57663&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57663&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57663&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57663&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57663&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57663&report=yes
Search -- http://master.php.net/manage/user-notes.php