Re: overloading members. aghhh!!!

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

 



Then if i make this

$foo = new foo();
$foo->ID = 12;

what is happening??
if __Set and __Get only works if a member isn't exits,

How come I do this?
$foo->ID = 12;
if the member $ID is private???

I thought that this was possible because i have declared the two method set 
and get :P


"Jochem Maas" <jochem@xxxxxxxxxxxxx> escribió en el mensaje 
news:47417E21.6000203@xxxxxxxxxxxxxxxx
> 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


[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