re: PHP Typed Properties: Think Twice. VIEW POST

re: "First, you shouldn't be using public fields." It is cargo-cult that every OOP programmer has followed since eons. For example. public $field; ...

I second that!

Context is key here. There are objects in our daily life that are just a way to organise data. DTO's, entities and such. The integrity of those objects should be made sure from the outside anyway.

And then there are objects whose inner state is critical. It's objects where you might only want to expose properties via constructor and getters to control the state.

However, both types don't really justify hiding protected or private properties behind getters and setter that don't do anything else but to expose said properties as if they were public in the first place.

code of conduct - report abuse