Why is it not okay to access a property of a class, but it is okay to
access a method of the same class?
I'm new to PHP, and whenever I'm reading up on good practices, especially
relating to OOP, I often see statements such as "don't expose local
variables to the global space, use a getter method or retrieval method
instead".
I understand why we don't want to pollute the global namespace, but at
what point does it become simply ridiculous to call a getter method just
to access a simple property? I think this shows massive hypocrisy. We're
willing to expose and call methods outside of the class definition, but
not simple variables? Why is this? Isn't a method much more complex?
Forgive me if my confusion is missplaced. I'm genuinely interested in
understanding OOP best practices.
No comments:
Post a Comment