Merge pull request #31 from maxmind/dave/boolean-false-not-null

Return false instead of null for non-true boolean attributes
This commit is contained in:
Gregory Oschwald
2014-10-28 10:49:29 -07:00
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");
}