Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Created January 13, 2015 14:02
Show Gist options
  • Save mageekguy/101480a32660c4860bb6 to your computer and use it in GitHub Desktop.
Save mageekguy/101480a32660c4860bb6 to your computer and use it in GitHub Desktop.
ArrayAccess and "undefined" key
<?php
class foo implements arrayAccess
{
public $values;
function offsetSet($key, $value)
{
var_dump($key);
$this->values[$key ?: sizeof($this->values)] = $value;
}
function offsetGet($key)
{
}
function offsetExists($key)
{
}
function offsetUnset($key)
{
}
}
$foo = new foo;
$foo[] = 'bar';
var_dump($foo->values);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment