I want to set a property value within my class. I can do it without a setter and a getter but I want to know the “correct” way to approach this. This is for a login script so the property and the setter are both private.
Should I just set the property directly or use a setter and a getter?
This is probably mainly a matter of personnal preference…
If you have to set the private property from a method of the class, I would say that you can access that property directly.
A reason to use an setter/getter, in that kind of situation, would be if you want to ensure that some condition or calculation is made on the data each time the property is set.
As a sidenote : of course, if your want to access your private property from outside the class, you’ll have to use to public setter/getter — but it doesn’t seem to be what you are trying to do here.