mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-10-31 10:39:59 +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) | ||||
| - 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) | ||||
| - Enh #19804: Remove the unnecessary call to `$this->oldAttributes` in `BaseActiveRecord::getDirtyAttributes()` (thiagotalma) | ||||
|  | ||||
| 2.0.47 November 18, 2022 | ||||
| ------------------------ | ||||
|  | ||||
| @ -639,7 +639,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface | ||||
|             } | ||||
|         } else { | ||||
|             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; | ||||
|                 } | ||||
|             } | ||||
| @ -1756,18 +1756,18 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param string $attribute | ||||
|      * @param mixed $value | ||||
|      * @param mixed $newValue | ||||
|      * @param mixed $oldValue | ||||
|      * @return bool | ||||
|      * @since 2.0.48 | ||||
|      */ | ||||
|     private function isAttributeDirty($attribute, $value) | ||||
|     private function isValueDifferent($newValue, $oldValue) | ||||
|     { | ||||
|         $old_attribute = $this->oldAttributes[$attribute]; | ||||
|         if (is_array($value) && is_array($this->oldAttributes[$attribute])) { | ||||
|             $value = ArrayHelper::recursiveSort($value); | ||||
|             $old_attribute = ArrayHelper::recursiveSort($old_attribute); | ||||
|         if (is_array($newValue) && is_array($oldValue)) { | ||||
|             $newValue = ArrayHelper::recursiveSort($newValue); | ||||
|             $oldValue = ArrayHelper::recursiveSort($oldValue); | ||||
|         } | ||||
|  | ||||
|         return $value !== $old_attribute; | ||||
|         return $newValue !== $oldValue; | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Thiago Talma
					Thiago Talma