Last active
December 16, 2016 18:44
-
-
Save willemwollebrants/3462ba8ed55d8fd8524b378b4546f0c7 to your computer and use it in GitHub Desktop.
This file contains 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 | |
//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