Re: overloading members. aghhh!!!

From: Date: Mon, 19 Nov 2007 12:14:25 +0000
Subject: Re: overloading members. aghhh!!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-264774@lists.php.net to get a copy of this message
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. so instead dump your data in an array or something private $data = array( 'ID' => null, 'Name' => null, 'LastName' => null, ); > > private function __get($var) > { > return $var; there is no such thing as 'implicit class scope' $var will not refer to $this->var as you seem to expect. return isset($this->data[$var]) ? $this->data[$var] : null; > } > > private function __set($var,$value) > { > $var = $value; same thing here. if (array_key_exists($var, $this->data) $this->data[$var] = $value; > } > } >

« previous php.general (#264774) next »