Re: overloading members. aghhh!!!
| From: | Peter Ford | Date: | Tue, 20 Nov 2007 13:53:21 +0000 |
| Subject: | Re: overloading members. aghhh!!! | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-264859@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
> Kiketom wrote:
>> Hi all.
>> Yesterday i have looking for the overloading members
>>
>> Member overloading
>> void __set ( string name, mixed value )
>> mixed __get ( string name )
>>
>> As an example i put this code:
>>
>> class foo
>> {
>> private $ID;
>> private $Name;
>> private $LastName;
>
> when you declare these three as 'real' members, __get() and __set()
> will no longer be called - they are only called for non-existent members.
>
Nope, that's not true. If the members are private, or otherwise inaccessible,
__get() and __set() are called - I've used this in a few places to provide a
"read-only" member variable, e.g.:
class foo
{
private $bar=0;
public function __get($nm)
{
return $this->$nm;
}
public function __set($nm,$val)
{
if ($nm != 'bar')
{
$this->$nm = $val;
}
}
}