如何对ArrayObj
未定义的索引不敏感,我有时需要在日志中使用未定义的索引示例
$this->log['some']['other']['info']++
这是我的尝试:
class arrayInSensitive extends \arrayObject{
var $data = array();
public function offsetGet($name) {
if(!array_key_exists($name,$this->data)) $this->data[$name]=new arrayInSensitive();
return $this->data[$name];
}
public function offsetSet($name, $value) {
$this->data[$name] = $value;
}
public function offsetExists($name) {
return (array_key_exists($name,$this->data));
}
public function offsetUnset($name) {
unset($this->data[$name]);
}
}
怎么做 ?