Getters and setters, or nah? https://media.tenor.com/Pt-gRP6TeMoAAAAC/yes-im-old-school-cass-dekennessy.gif #devs
The code I'm finding online never seem to use them. Have they gone out of style?
It depends if you need to perform validation and transformation. Also if you variables are private or not
I only use them when my get or set needs to do something non-standard. Using them everywhere when the language supports default getters and setters on class properties just creates unnecessary clutter.
You mean, as you can access over the __construct() ?
I think so? You might be thinking in PHP-specific terms I'm not familiar with. As an example, though, I recently wrote a class for my day job that had a public `value` prop and a private `_value` state. Changes to `value` updated `_value`, but not vice-versa, because the public one had a change listener and I needed a way to change it without triggering the listener. However, were it not for that case, I would have just used a single class property `value` with no explicit getters or setters, because TypeScript defines get and set behavior by default on classes, without the need for developer code.
Hmm. I don't think PHP does that.
I think I picked up the habit from working with Doctrine and Symfony. I think they they're strict about that.