5

My question is - why the usage of protected members in class in Magento 2 is discouraged?

I looked into other questions that ask about warnings of the PHP CodeSniffer for Magento 2, but nobody addressed this specific warning - "Use of protected class members is discouraged".

In my understanding avoiding the usage of protected members conflicts with the idea of inheritance. That is, if I want to extend the functionality of the protected method and therefore I might need to touch the protected member, I wont be able to do that.

Any thoughts?

| improve this question | | | | |
2

As far as I'm aware some protected class members will need to be protected. I have seen solutions like this applied to phpcs, basically removing the warning:

https://github.com/eMerchantPay/magento2-emp-plugin/blob/master/.phpcs.xml

Notice these standards have not been updated in 4 months and are not yet working with the latest version of Code Sniffer, so I'm pretty sure an update is due.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.