Re: overloading members. aghhh!!!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
		}
	}
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux