<?php
class A {
protected $var1 = 'foo_1';
protected $var2 = 'foo_2';
public function __call($name, $arg) {
$action = substr($name, 0, 3);
$var_name = strtolower(substr($name, 3));
if($action == 'get') {
return $this->__get($var_name);
} elseif($action == 'set') {
$this->__set($var_name, $arg[0]);
return 1;
} else {
/// Обработка ошибок
}
}
protected function __get($name) {
return $this->$name;
}
protected function __set($name, $value) {
$this->$name = $value;
}
}
$Object = new A();
echo $Object->getVar1().'<br />';
$Object->setVar1('Something else');
echo $Object->getVar1().'<br />';