Still didn't find the original, but remembered the actual trick, so I reimplemented it:
(my internet connection being down yesterday gave me the time)
class FancyArray implements ArrayAccess {
var $_keys = array();
var $_values = array();
function offsetExists($name) {
return $this->key($name) !== FALSE;
}
function offsetGet($name) {
$key = $this->key($name);
if ($key !== FALSE) {
return $this->_values[ $key ];
}
else {
trigger_error("Undefined offset: {{$name}} in FancyArray __FILE__ on line __LINE__", E_USER_NOTIC
return NULL;
}
}
function offsetSet($name, $value) {
$key = $this->key($name);
if ($key !== FALSE) {
$this->_values[$key] = $value;
}
else {
$key = end(array_keys($this->_keys)) + 1;
$this->_keys[$key] = $name;
$this->_values[$key] = $value;
}
}
function offsetUnset($name) {
$key = $this->key($name);
unset($this->_keys[$key]);
unset($this->_values[$key]);
}
function key($obj) {
return array_search($obj, $this->_keys);
}
}
It's basically ArrayAcces and a disparage array for keys and one for values. Very basic, but it allows:
$x = new FancyArray();
$x[array(1,2,3,4)] = $something_else; // arrays as key
print $x[new SplFileInfo("x")]; // well, if set beforehand