*/ class GetterSetter { public function __call($method, $arguments) { $property = lcfirst(substr($method, 3)); $prefix = strtolower(substr($method, 0,3)); if ($prefix == 'set' && ! isset($arguments[0])) { trigger_error(sprintf('Missing argument 1 for %s::%s()', get_class($this), $method)); return; } if (! property_exists(get_class($this), $property)) { trigger_error(sprintf('Undefined method %s::%s()', get_class($this), $method)); return; } switch ($prefix) { case 'get': return $this->$property; case 'set': return $this->$property = $arguments[0]; } } public function __get($property) { return call_user_func_array(array($this, 'get'.ucfirst($property)), array()); } public function __set($property, $value) { return call_user_func_array(array($this, 'set'.ucfirst($property)), array($value)); } }