Created
July 17, 2013 05:02
-
-
Save t-cyrill/6017812 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class ArrayChaser implements ArrayAccess { | |
| private $array_ref; | |
| private $log = array(); | |
| public function __construct(array &$ref) | |
| { | |
| $this->array = &$ref; | |
| } | |
| public function offsetExists($offset) | |
| { | |
| $this->log[] = array('ISSET', $offset); | |
| return isset($this->array[$offset]); | |
| } | |
| public function offsetGet($offset) | |
| { | |
| $this->log[] = array('GET', $offset); | |
| return $this->array[$offset]; | |
| } | |
| public function offsetSet($offset, $value) | |
| { | |
| $this->log[] = array('SET', $offset); | |
| if (!isset($offset)) { | |
| $this->array[] = $value; | |
| } else { | |
| $this->array[$offset] = $value; | |
| } | |
| } | |
| public function offsetUnset($offset) | |
| { | |
| $this->log[] = array('UNSET', $offset); | |
| unset($this->array[$offset]); | |
| } | |
| } | |
| $array = array(); | |
| $ref = new ArrayChaser($array); | |
| $ref['hoge'] = 'foo'; | |
| $ref['fuga'] = 'foo'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment