-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BC break: Calling a method unnecessarily #19804
Conversation
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`.
$old_attribute = $this->oldAttributes[$attribute]; | ||
if (is_array($value) && is_array($this->oldAttributes[$attribute])) { | ||
$old_attribute = $this->_oldAttributes[$attribute]; | ||
if (is_array($value) && is_array($this->_oldAttributes[$attribute])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I read this correctly here might be a problem when $this->_oldAttributes
is null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yii2/framework/db/BaseActiveRecord.php
Line 642 in 2a7c6f2
if (isset($names[$name]) && (!array_key_exists($name, $this->_oldAttributes) || $this->isAttributeDirty($name, $value))) { |
In theory, this check ensures that this problem will never occur.
What broke? Were there error messages, wrong data? |
Thanks for posting in our issue tracker.
Thanks! This is an automated comment, triggered by adding the label |
The problem was because I was overriding the I only opened the PR because it may be that the same problem occurs with other people. In my understanding, it makes no sense to force the call in the Anyway, MY problem I already solved. |
I think we could change it to use private property indeed but with additional check for null. |
@bizley done |
Would you please a line for CHANGELOG? |
@samdark done! |
Sorry, just noticed that this is wrong, let's make it like that for example
then we can just call it like
Otherwise we compare $value to an empty array if not set in old attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please modify as per my comment.
Thanks. |
Owww... GitHub did not update the comments before I hit the merge button :( |
Reverted commit for now. @thiagotalma would you please fix it as @bizley suggested? |
…ibutes` to avoid calling a method unnecessarily" This reverts commit 246a581.
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
.