MINOR make sure DataObject::setField() can only be pased a scalar, or a DBField.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@82486 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Tom Rix 2009-07-23 00:31:52 +00:00
parent 77ab3e6038
commit d5d8cf15f6

View File

@ -1974,11 +1974,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* @param mixed $val New field value
*/
function setField($fieldName, $val) {
// Situation 1: Passing a DBField
if($val instanceof DBField) {
$val->Name = $fieldName;
$this->record[$fieldName] = $val;
// Situation 1: Passing an object
if(is_object($val)) {
if($val instanceof DBField) {
$val->Name = $fieldName;
$this->record[$fieldName] = $val;
} else {
user_error('DataObject::setField: passed an object that is not a DBField', E_USER_WARNING);
}
// Situation 2: Passing a literal
} else {
$defaults = $this->stat('defaults');