note 112816 deleted from class.arrayaccess by frozenfire
| From: | frozenfire@php.net | Date: | Fri, 07 Mar 2014 23:01:39 +0000 |
| Subject: | note 112816 deleted from class.arrayaccess by frozenfire | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198829@lists.php.net to get a copy of this message | ||
Note Submitter: gk at anuary dot com
----
If you ever needed to have ArrayAccess for a multidimensional array, you can achieve that using
runkit_ extension.
<?php
class Test implements \ArrayAccess {
private
$input = [];
public function __construct () {
$this->input = ['foo' => ['bar' => 'qux']];
}
public function offsetExists ($offset) {}
public function offsetGet ($offset) {}
public function offsetSet ($offset, $value) {}
public function offsetUnset ($offset) {}
}
runkit_method_redefine ('Test', 'offsetGet', '&$offset',
'return $this->input[$offset];');
$ui = new Test;
var_dump($ui['foo']['bar']); // string(3) "qux"
?>