-
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
Use static:: to support late static bindings in Invoice and Creditmemo #9813
Conversation
Instead of replacing self::$_states you could use plugins (interceptors) for your needs. |
@ihor-sviziev, have you even read the doc you've just linked? Seems not.
Let's not be too presumptuous about plugins: there are still valid cases when overriding the class via |
@korostii you could create after plugin for method getStates and add your own state to result. You don't need to use static variables in these classes. |
Except... |
@korostii ah, it's my mistake, sorry for that. @vrann what do you think about this issue? |
Extending core classes is not a recommended way of customization nowadays. Why |
@orlangur I suspect it is a BC break at this point. |
@ishakhsuvarov ah, yeah, in such case we would force class instantiation. So, the only way we can go in long-term is to encapsulate states in separate new class and deprecate this method (but still use within this new class until BC break allowed). |
Description
When using self:: to call static properties and static methods late static binding (see http://php.net/manual/en/language.oop5.late-static-bindings.php) will not be supported. Instead static:: should be used.
When a class inherits from Magento\Sales\Model\Order\Invoice or Magento\Sales\Model\Order\Creditmemo and has its own implementation of the static method (or property) this implementation might not be called.
This is not a bug in the Magento code base but it would improve the code for customisation.
Example
I have class ExtendedInvoice which inherits from Invoice. It has its own implementation of getStates() because I want to add an extra state.
Now when getStateName() is called on an instance of ExtendedInvoice, the getStates() method of the parent class will be used instead of my implementation and thus my extra state will be unknown.
When changing self:: to static:: as in my commit the correct implementation of getStates() will be called.