|
Posted by Vince Morgan on 04/20/07 21:18
"Steve" <no.one@example.com> wrote in message
news:1P9Wh.1936$lq2.1174@newsfe04.lga...
> | class C_Obj
> | {
> | private $Obj=array('h'=>10,'i'=>12);
> |
> | private function getVal($name)
> | {
> | return $this->Obj[$name];
> | }
> | function &__set($name, $val)
> | {
> | $name = $val;
> | }
> | function __get($name)
> | {
> | return self::getVal($name);
> | }
> | }
>
> yes, but here i must agree with the others. the reason why this works is
> because you don't have the object's interface exposed. therefore, php
> executes __set/__get. so in this case, the other posters are correct.
>
Wellllll, errrr, I just tried what is below, and it works on my machine.
class C_Obj
{
public $Obj=array('h'=>10,'i'=>12);
public function getVal($name)
{
return $this->Obj[$name];
}
function &__set($name, $val)
{
$name = $val;
}
function __get($name)
{
return self::getVal($name);
}
}
$obj = new C_Obj;
$obj->h=5;
echo $obj->h."<br>";
echo $obj->getVal('h');
Of course I'ts now 7.15am and I haven't slept, so I could be delusional : )
Navigation:
[Reply to this message]
|