0
如何使ArrayObj
在不受未定義的指標,我有時需要在登錄使用不確定的指數例如PHP arrayObj不受undegined指數
$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]);
}
}
怎麼辦它呢?