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?

1 Answer 1


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:


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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