note 82220 deleted from language.oop5.overloading by cmb

From: Date: Sun, 03 Mar 2019 11:35:22 +0000
Subject: note 82220 deleted from language.oop5.overloading by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210306@lists.php.net to get a copy of this message
Note Submitter: nospam michael AT netkey DOT at nospam ---- you CAN write into ARRAYS by using __set and __get magic functions. as has been mentioned before $obj->var['key'] = 'test'; does call the __get method of $obj, and there is no way to find out, if the method has been called for setting purposes. the solution is quite simple: use __get to return the array by reference. then you can write into it: <?php class setter{ private $_arr = array(); public function __set($name, $value){ $this->_arr[$name] = $value; } public function &__get($name){ if (isset($this->_arr[$name])){ return $this->_arr[$name]; } else return null; } } ?>

« previous php.notes (#210306) next »