Ask HN: Do you use Setters and Getters in PHP?
I'm ashamed to admit that I have known about setters and getters for a very long time, and used them sparsely, mostly due to what I thought were time constraints.
What I learned a couple years ago is, NOT using them can be a bigger loss of time when you're updating something a lot. In an effort to write better stuff I start doing tons more data hiding, and using setters and getters (like most people do in other languages anyway) and found the following things:
I can sort of enforce type safety in PHP. I can create better interfaces and hide implementation better. Sanitizing the data is far easier. Usually just have to change it one place. Code is much cleaner in many places.
So my question is, are you using them? Is there any good reason not to?