note 84627 modified in ref.spl by thiago
| From: | thiago@php.net | Date: | Tue, 22 Jul 2008 16:56:58 +0000 |
| Subject: | note 84627 modified in ref.spl by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142506@lists.php.net to get a copy of this message | ||
I have to correct my implementation from before. The example before only supported correct
read-access but failed on setting new values after creation of the ArrayMultiObject. Also i had to
correct a bug that occured from my CopyPasteChange into the comment textarea.
This snippet now hopefully implements a fully functional multidimensional array, represented by an
ArrayObject:
<?php
class ArrayMultiObject extends ArrayObject
{
function __construct($array, $flags = 0, $iterator_class = "ArrayIterator")
{
$objects = array();
foreach($array AS $key => $value) {
if(is_array($value)) {
$objects[$key] = new ArrayMultiObject($value, $flags, $iterator_class);
} else {
$objects[$key] = $value;
}
}
parent::__construct($objects, $flags, $iterator_class);
}
public function offsetSet($name, $value)
{
if(is_array($value)) {
$value = new ArrayMultiObject($value);
}
return parent::offsetSet($name, $value);
}
}
?>
--was--
I have to correct my implementation from before. The example before only supported correct
read-access but failed on setting new values after creation of the ArrayMultiObject. Also i had to
correct a bug that occured from my CopyPasteChange into the comment textarea.
This snippet now hopefully implements a fully functional multidimensional array, represented by an
ArrayObject:
class ArrayMultiObject extends ArrayObject
{
function __construct($array, $flags = 0, $iterator_class = "ArrayIterator")
{
$objects = array();
foreach($array AS $key => $value) {
if(is_array($value)) {
$objects[$key] = new ArrayMultiObject($value, $flags, $iterator_class);
} else {
$objects[$key] = $value;
}
}
parent::__construct($objects, $flags, $iterator_class);
}
public function offsetSet($name, $value)
{
if(is_array($value)) {
$value = new ArrayMultiObject($value);
}
return parent::offsetSet($name, $value);
}
}
http://php.net/manual/en/ref.spl.php