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;
> }
> }
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php