public function __set($name, $val) { try { return parent::__set($name, $val); } catch (CException $e) { $method_name = StringHelper::underscoreToCamelcase($name); $method_name = 'set' . ucfirst($method_name); if (method_exists($this, $method_name)) { return $this->{$method_name}($val); } else { throw new CException($e->getMessage()); } } }
public function __get($name) { try { return parent::__get($name); } catch (CException $e) { $method_name = StringHelper::underscoreToCamelcase($name); if (method_exists($this, 'get' . ucfirst($method_name))) { return $this->{$method_name}; } else { $attr = StringHelper::camelCaseToUnderscore($name); if (mb_substr($attr, 0, 4) == 'get_') { $attr = mb_substr($attr, 4); } $attr = get_class($this) . '.' . $attr; throw new CException('Не определено свойство ' . $attr); } } }