|
Posted by Steve on 04/20/07 20:59
| 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.
what the op is wanting to do with __set/__get is actually define a public
var and handle its getting/setting with private methods. the op proposed
that __set/__get would be the middle-man. it won't in any current release of
php. i'm hoping in future versions that it will, as this would make it very
similar to other oop enabled scripting languages...those that are more
robust at present.
Navigation:
[Reply to this message]
|