mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-01 11:39:41 +08:00
BC break: Calling a method unnecessarily (#19810)
* BC: Calling a method unnecessarily Making an indirect call to the `$this->getOldAttributes()` method caused my code to break. I understand that the correct thing would be to reference `$this->_oldAttributes`. * Null check * Update CHANGELOG.md * Change isAttributeDirty() method to isValueDifferent() * Update CHANGELOG.md
This commit is contained in:
@ -24,6 +24,7 @@ Yii Framework 2 Change Log
|
|||||||
- Bug #19770: Fix `yii\mutex\MysqlMutex` `keyPrefix` expression param binding (kamarton)
|
- Bug #19770: Fix `yii\mutex\MysqlMutex` `keyPrefix` expression param binding (kamarton)
|
||||||
- Enh #19794: Add caching in `yii\web\Request` for `getUserIP()` and `getSecureForwardedHeaderTrustedParts()` (rhertogh)
|
- Enh #19794: Add caching in `yii\web\Request` for `getUserIP()` and `getSecureForwardedHeaderTrustedParts()` (rhertogh)
|
||||||
- Bug #19795: Fix `yii\web\Response::redirect()` to prevent setting headers with URL containing new line character (bizley)
|
- Bug #19795: Fix `yii\web\Response::redirect()` to prevent setting headers with URL containing new line character (bizley)
|
||||||
|
- Enh #19804: Remove the unnecessary call to `$this->oldAttributes` in `BaseActiveRecord::getDirtyAttributes()` (thiagotalma)
|
||||||
|
|
||||||
2.0.47 November 18, 2022
|
2.0.47 November 18, 2022
|
||||||
------------------------
|
------------------------
|
||||||
|
|||||||
@ -639,7 +639,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($this->_attributes as $name => $value) {
|
foreach ($this->_attributes as $name => $value) {
|
||||||
if (isset($names[$name]) && (!array_key_exists($name, $this->_oldAttributes) || $this->isAttributeDirty($name, $value))) {
|
if (isset($names[$name]) && (!array_key_exists($name, $this->_oldAttributes) || $this->isValueDifferent($value, $this->_oldAttributes[$name]))) {
|
||||||
$attributes[$name] = $value;
|
$attributes[$name] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1756,18 +1756,18 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $attribute
|
* @param mixed $newValue
|
||||||
* @param mixed $value
|
* @param mixed $oldValue
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @since 2.0.48
|
||||||
*/
|
*/
|
||||||
private function isAttributeDirty($attribute, $value)
|
private function isValueDifferent($newValue, $oldValue)
|
||||||
{
|
{
|
||||||
$old_attribute = $this->oldAttributes[$attribute];
|
if (is_array($newValue) && is_array($oldValue)) {
|
||||||
if (is_array($value) && is_array($this->oldAttributes[$attribute])) {
|
$newValue = ArrayHelper::recursiveSort($newValue);
|
||||||
$value = ArrayHelper::recursiveSort($value);
|
$oldValue = ArrayHelper::recursiveSort($oldValue);
|
||||||
$old_attribute = ArrayHelper::recursiveSort($old_attribute);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value !== $old_attribute;
|
return $newValue !== $oldValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user