|
Posted by Steve on 04/20/07 22:54
"Vince Morgan" <vinhar@REMOVEoptusnet.com.au> wrote in message
news:4629316b$0$5746$afc38c87@news.optusnet.com.au...
| "Steve" <no.one@example.com> wrote in message
| news:MaaWh.1449$go5.1225@newsfe12.lga...
| > if you had $h as a public variable and then tried to say $obj->h = 'some
| > value', you'd never have __set be called by php.
| >
| > give that a try and see what i mean.
| >
| >
|
| class C_Obj
| {
| public $h=5;
|
| function __set($name, $val)
| {
| $name = $val;
| }
| function __get($name)
| {
| return self::getVal($name);
| }
| }
|
| $obj = new C_Obj;
| $obj->h=15;
| echo $obj->h."<br>";
|
| Either my head is now brocken, or my php engine is.
| If I understand you correctly, and it's very likely I'm not, the above
| shouldn't work. But it does.
try this...notice my modification. it clearly shows that __set is NOT called
when setting $obj->h.
class C_Obj
{
public $h=5;
function __set($name, $val)
{
$this->Obj[$name] = $val;
echo '<pre>__set says: ' . $name . '...' . $val . '</pre>';
}
function __get($name)
{
return self::getVal($name);
}
private function getVal($name)
{
return $this->Obj[$name];
}
}
$obj = new C_Obj;
$obj->h=15;
echo '<pre>does NOT trigger __set : ' . $obj->h . '</pre>';
$obj->yourMomma = 'nice lady. no, i really mean it :)';
Navigation:
[Reply to this message]
|