$value) { $this->$name = $value; } } /** * Set a field * * @param string $name * @param mixed $value * @throws App_Model_OutOfBoundsException When field does not exist * @return void */ public function __set($name, $value) { $method = '_set' . ucfirst($name); if (method_exists($this, $method)) { $this->{$method}($value); } else if (in_array($name, $this->_fields)) { $this->_values[$name] = $value; } else { throw new App_Model_OutOfBoundsException('Field with name ' . $name . ' does not exist'); } } /** * Get a field * * @param string $name * @throws App_Model_OutOfBoundsException When field does not exist * @return mixed */ public function __get($name) { $method = '_get' . ucfirst($name); if (method_exists($this, $method)) { return $this->{$method}(); } else if (in_array($name, $this->_fields)) { if (!array_key_exists($name, $this->_values)) { throw new App_Model_RuntimeException('Trying to accessing field ' . $name . ' which value was not set yet'); } return $this->_values[$name]; } else { throw new App_Model_OutOfBoundsException('Field with name ' . $name . ' does not exist'); } } }