Weird PHP magic getter on an array -


i have weird issues magic getter/isset. have myobject defines magic getter/isset:

private $_data = array();  public function __get($name) {     if (array_key_exists($name, $this->_data)) return $this->_data[$name];     throw new exception($name.': property doesn\'t exist.'); }  public function __isset($name) {     return isset($this->_data[$name]); } 

if call:

isset($myobject->notexisting); empty($myobject->notexisting); 

i have correct behaviour (__isset() called), while if call:

isset($myobject->notexisting['ok'])); empty($myobject->notexisting['ok'])); 

__isset() not called while __get() is.

this seems weird me php should first check $myobject->notexisting existence before trying it, shouldn't ?

according docs:

__isset() triggered calling isset() or empty() on inaccessible properties.

in isset($myobject->notexisting); isset applies notexisting property of $myobject.

in isset($myobject->notexisting['ok'])); isset applies ok element of $myobject->notexisting array.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -