note 112816 added to class.arrayaccess
| From: | gk at anuary dot com | Date: | Fri, 26 Jul 2013 05:43:33 +0000 |
| Subject: | note 112816 added to class.arrayaccess | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195775@lists.php.net to get a copy of this message | ||
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"
?>
----
Server IP: 69.147.83.199
Probable Submitter: 91.85.156.201
----
Manual Page -- http://php.net/manual/en/class.arrayaccess.php
Edit -- https://master.php.net/note/edit/112816
Del: integrated -- https://master.php.net/note/delete/112816/integrated
Del: useless -- https://master.php.net/note/delete/112816/useless
Del: bad code -- https://master.php.net/note/delete/112816/bad+code
Del: spam -- https://master.php.net/note/delete/112816/spam
Del: non-english -- https://master.php.net/note/delete/112816/non-english
Del: in docs -- https://master.php.net/note/delete/112816/in+docs
Del: other reasons-- https://master.php.net/note/delete/112816
Reject -- https://master.php.net/note/reject/112816
Search -- https://master.php.net/manage/user-notes.php