Skip to content

Instantly share code, notes, and snippets.

@t-cyrill
Created July 17, 2013 05:02
Show Gist options
  • Select an option

  • Save t-cyrill/6017812 to your computer and use it in GitHub Desktop.

Select an option

Save t-cyrill/6017812 to your computer and use it in GitHub Desktop.
<?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