Skip to content

Commit 4e1fc27

Browse files
committed
Merge branch 'master' of github.com:yiisoft/yii2
2 parents a5a2481 + e9d7a22 commit 4e1fc27

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

framework/yii/db/ActiveRecord.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,16 @@ public function getAttribute($name)
523523
* Sets the named attribute value.
524524
* @param string $name the attribute name
525525
* @param mixed $value the attribute value.
526+
* @throws InvalidParamException if the named attribute does not exist.
526527
* @see hasAttribute
527528
*/
528529
public function setAttribute($name, $value)
529530
{
530-
$this->_attributes[$name] = $value;
531+
if (isset($this->_attributes[$name]) || isset($this->getTableSchema()->columns[$name])) {
532+
$this->_attributes[$name] = $value;
533+
} else {
534+
throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".');
535+
}
531536
}
532537

533538
/**
@@ -567,11 +572,16 @@ public function getOldAttribute($name)
567572
* Sets the old value of the named attribute.
568573
* @param string $name the attribute name
569574
* @param mixed $value the old attribute value.
575+
* @throws InvalidParamException if the named attribute does not exist.
570576
* @see hasAttribute
571577
*/
572578
public function setOldAttribute($name, $value)
573579
{
574-
$this->_oldAttributes[$name] = $value;
580+
if (isset($this->_oldAttributes[$name]) || isset($this->getTableSchema()->columns[$name])) {
581+
$this->_oldAttributes[$name] = $value;
582+
} else {
583+
throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".');
584+
}
575585
}
576586

577587
/**

0 commit comments

Comments
 (0)