-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Getter methods shouldn't change values #1133
Comments
In my opinion magento is not changing the value, it is setting the default value if there is no value. |
A default value should be set when the object is instantiated and/or the values are set, not when the value is read for the first time. The The behaviour was introduced in CE 1.6.1.0 and it led to a nasty bug in a third-party extension we use so I figured I might suggest this. |
I agree with @mzeis - if it's a default, set in constructor. Sometimes getters may cache the result, and sometimes this is necessary for performance reasons. But it is risky - a source for insidious bugs. This is potentially making performance worse as every get call is doing the if statement. So in this case, no good reason for it. That said, not sure it will be a core team priority to go on a hunt to fix them compared to other work. |
@mzeis - I'll write this up as a github/bug on product model ( MAGETWO-35512 ); if you/or anyone else finds more please open a separate github issue and we'll open an appropriate bug on our end to handle. We'll triage them as appropriate. |
Thanks! I'm happy with that. |
@mzeis, what do you think about - call it "lazy setting"? :) |
Lazy setting is nice. :-) If you're into alliteration you can also call it "delayed defaulting". |
I'd say that the original case and case from @Eydamos are different.
Looks like, it's a bug in this particular implementation. If it would not impact Unless I'm missing something... |
Looks like (MAGETWO-35760) is a similar bug ( already being worked ). Linking issues.; Ignore this one.... 35760 isn't related. MAGETWO-35512 is the linked internal Jira issue for this thread. |
@mzeis, issue in getStatus() method was fixed and available from 0.74.0-beta13. Could you check it? |
@vpelipenko Thanks, looks good! |
Magento 2 sometimes changes values in getter methods. This can lead to undesirable side effects.
An example from the product model:
I'm aware this is a very general issue and has to be tackled over time during the whole code refactoring process but it is important.
The text was updated successfully, but these errors were encountered: