Skip to content

Instantly share code, notes, and snippets.

@willemwollebrants
Last active December 16, 2016 18:44
Show Gist options
  • Save willemwollebrants/3462ba8ed55d8fd8524b378b4546f0c7 to your computer and use it in GitHub Desktop.
Save willemwollebrants/3462ba8ed55d8fd8524b378b4546f0c7 to your computer and use it in GitHub Desktop.
<?php
//yikes
class ArrayArrayObject extends ArrayObject
{
public function offsetSet($index, $value)
{
array_map(function ($k) use ($value) {
parent::offsetSet($k, $value);
}, (array)$index);
}
public function offsetGet($index)
{
if ( ! is_array($index)) {
return parent::offsetGet($index);
}
$rv = [];
array_map(function ($k) use (&$rv) {
$rv[$k] = parent::offsetGet($k);
}, $index);
return $rv;
}
}
$aao = new ArrayArrayObject();
$aao[['a', 'b']] = 'foo';
var_dump($aao['a']); // = 'foo'
var_dump($aao['b']); // = 'foo'
var_dump($aao[['a', 'b', 'c']]); // Notice Undefined Index 'c', returns ['a'=>'foo', 'b'=>'foo', 'c'=>null];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment