public function &__get($field)
{
$v = null;
$camelCaseField = str_replace(' ', '', ucwords(str_replace('_', ' ', $field)));
$getterMethod = 'get' . $camelCaseField;
if (!in_array($field, $this->_inGetter) && method_exists($this, $getterMethod)) {
// Custom getter method
$this->_inGetter[$field] = true;
$v = call_user_func([$this, $getterMethod]);
unset($this->_inGetter[$field]);
} else {
// We can't use isset because it returns false for NULL values
if (array_key_exists($field, $this->_dataModified)) {
$v =& $this->_dataModified[$field];
} elseif (array_key_exists($field, $this->_data)) {
// if the value is an array or an object, copy it to dataModified first
// and return a reference to that
if (is_array($this->_data[$field])) {
$this->_dataModified[$field] = $this->_data[$field];
$v =& $this->_dataModified[$field];
} elseif (is_object($this->_data[$field])) {
$this->_dataModified[$field] = clone $this->_data[$field];
$v =& $this->_dataModified[$field];
} else {
$v =& $this->_data[$field];
}
} elseif ($relation = $this->relation($field)) {
$v =& $relation;
}
}
return $v;
}