/** * Get an attribute of the object * * @see \ActiveRecord\Model::__get() * @param string $name * @return mixed The value of the field */ public function &__get($name) { // Camelize the name $camelized_name = Inflector::instance()->camelize($name); // Check for getter if (method_exists($this, "get_{$name}")) { $name = "get_{$name}"; $value = $this->{$name}(); return $value; } elseif (method_exists($this, "get{$camelized_name}")) { $name = "get{$camelized_name}"; $value = $this->{$name}(); return $value; } elseif ($name === "id") { // Is the name an "id"? $formatted_attribute = $this->formatIntegerAttribute($name); return $formatted_attribute; } elseif (Utils::endsWith($name, '_at')) { // Does the name end with "_at"? $formatted_attribute = $this->formatTimeAttribute($name); return $formatted_attribute; } elseif (Utils::startsWith($name, 'is_')) { // Does the name start with "is_"? $formatted_attribute = $this->formatBooleanAttribute($name); return $formatted_attribute; } // Otherwise, just use our parent's magic getter return parent::__get($name); }