yii\db\BaseActiveRecord::isAttributeChanged PHP Method

isAttributeChanged() public method

Returns a value indicating whether the named attribute has been changed.
public isAttributeChanged ( string $name, boolean $identical = true ) : boolean
$name string the name of the attribute.
$identical boolean whether the comparison of new and old value is made for identical values using `===`, defaults to `true`. Otherwise `==` is used for comparison. This parameter is available since version 2.0.4.
return boolean whether the attribute has been changed
    public function isAttributeChanged($name, $identical = true)
    {
        if (isset($this->_attributes[$name], $this->_oldAttributes[$name])) {
            if ($identical) {
                return $this->_attributes[$name] !== $this->_oldAttributes[$name];
            } else {
                return $this->_attributes[$name] != $this->_oldAttributes[$name];
            }
        } else {
            return isset($this->_attributes[$name]) || isset($this->_oldAttributes[$name]);
        }
    }

Usage Example

 /**
  * Returns a value indicating whether the named attribute has been changed.
  * @param string $name the name of the attribute
  * @return boolean whether the attribute has been changed
  */
 public function isAttributeChanged($name, $depth = 2)
 {
     if (is_array($this->getAttribute($name))) {
         $new = $this->getAttribute($name);
         $old = $this->getOldAttribute($name);
         if ($depth < 1) {
             $depth = 1;
         }
         return self::isArrayChanged($new, $old, $depth);
     } else {
         return BaseActiveRecord::isAttributeChanged($name);
     }
 }