Re: overloading members. aghhh!!!
| From: | Kiketom | Date: | Mon, 19 Nov 2007 12:25:20 +0000 |
| Subject: | Re: overloading members. aghhh!!! | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-264775@lists.php.net to get a copy of this message | ||
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@iamjochem.com> escribió en el mensaje
news:47417E21.6000203@iamjochem.com...
> 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;
>
>> }
>> }
>>