Return false instead of null for boolean attributes

This commit is contained in:
Dave Rolsky
2014-10-28 10:27:18 -05:00
parent caf91dd247
commit c44053c276
5 changed files with 32 additions and 6 deletions
+9 -1
View File
@@ -23,7 +23,15 @@ abstract class AbstractModel implements \JsonSerializable
*/
protected function get($field)
{
return isset($this->raw[$field]) ? $this->raw[$field] : null;
if (isset($this->raw[$field])) {
return $this->raw[$field];
} else {
if (preg_match('/^is_/', $field)) {
return false;
} else {
return null;
}
}
}
/**
+5 -1
View File
@@ -25,7 +25,11 @@ abstract class AbstractRecord implements \JsonSerializable
if ($this->__isset($attr)) {
return $this->record[$key];
} elseif ($this->validAttribute($attr)) {
return null;
if (preg_match('/^is_/', $key)) {
return false;
} else {
return null;
}
} else {
throw new \RuntimeException("Unknown attribute: $attr");
}