Я рисую (JFF) для себя небольшой ORM, и для getter'ов/setter'ов применяю простой хак:
abstract class container
{
public function __get($name) {
$method = 'get_'.$name;
if( method_exists($this, $method) ) {
return $this->$method();
}
throw new Exception('Cannot get '.get_class($this).'::'.$name);
}
public function __set($name, $value) {
$method = 'set_'.$name;
if( method_exists($this, $method) ) {
$this->$method($value);
return;
}
throw new Exception('Cannot set '.get_class($this).'::'.$name);
}
}
Дальше всё очевидно. В модели пишу только те getter'ы и setter'ы, которые действительно нужны (вроде проверки корректности данных). Остальные свойства объявляю public'ом и не парюсь.
class something extends container
{
public $foo;
protected $bar; // read-only
function __construct($foo, $bar) {
$this->foo = $foo;
$this->bar = $bar;
}
function get_bar() {
return $this->bar;
}
}
$test = new something('a', 'b');
echo $test->foo; // 'a'
echo $test->bar; // 'b'
$test->bar = 'c'; // exception