Re: Real properties in PHP
| From: | Christian Schneider | Date: | Thu, 25 Aug 2005 10:37:48 +0000 |
| Subject: | Re: Real properties in PHP | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-18408@lists.php.net to get a copy of this message | ||
Marian Kostadinov wrote:
public getter fullName { // may also have () return "{$this->firstName} {$this->lastName}"; } public setter fullName ($value) { // may also not have ($value) but a special var. list ($this->firstName, $this->lastName) = explode (' ', $value, 2); }This can be easily done with function __get($name) {
$get = "get_$name";
return $this->$get();} function __set($name, $value) {
$set = "set_$name";
$this->$set($value);} in your base class (the function names are then get_fullName/set_fullName. - Chris