php arrayObj insensitive to undegined index -
how make arrayobj
in insensitive undefined index, need use undefined index example in logging
$this->log['some']['other']['info']++
here try:
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]); } }
how ?
just force specific case whenever reference index value
class arrayinsensitive extends \arrayobject{ var $data = array(); public function offsetget($name) { if(!array_key_exists(strtolower($name),$this->data)) $this->data[strtolower($name)]=new arrayinsensitive(); return $this->data[strtolower($name)]; } public function offsetset($name, $value) { $this->data[strtolower($name)] = $value; } public function offsetexists($name) { return (array_key_exists(strtolower($name),$this->data)); } public function offsetunset($name) { unset($this->data[strtolower($name)]); } }
Comments
Post a Comment