You are here: Re: Getting and Setting and best practise « PHP Programming Language « IT news, forums, messages
Re: Getting and Setting and best practise

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация