note 82220 added to language.oop5.overloading
| From: | nospammichaelATnetkeyDOTatnospam at osu1 dot php dot net | Date: | Tue, 01 Apr 2008 18:10:53 +0000 |
| Subject: | note 82220 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137824@lists.php.net to get a copy of this message | ||
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;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.127.91.224
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/82220
Del: integrated -- https://master.php.net/note/delete/82220/integrated
Del: useless -- https://master.php.net/note/delete/82220/useless
Del: bad code -- https://master.php.net/note/delete/82220/bad+code
Del: spam -- https://master.php.net/note/delete/82220/spam
Del: non-english -- https://master.php.net/note/delete/82220/non-english
Del: in docs -- https://master.php.net/note/delete/82220/in+docs
Del: other reasons-- https://master.php.net/note/delete/82220
Reject -- https://master.php.net/note/reject/82220
Search -- https://master.php.net/manage/user-notes.php