Re: overloading members. aghhh!!!

From: Date: Tue, 20 Nov 2007 18:39:06 +0000
Subject: Re: overloading members. aghhh!!!
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-264874@lists.php.net to get a copy of this message
Peter Ford wrote: > 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. Indeed. I did post back to say I was talking ****. If the members are private, or otherwise inaccessible, I believe that this was not always the case (i.e. that in older versions private members behaved the same way as public members with regard to __get()/__set() - I'm not sure but I think so) > __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; > } > } > } >

« previous php.general (#264874) next »