3 ms·
This seems to be making the code less readable and more like javascript. I much prefer public function getName(): string { return $this->name; } ove
by plopz 7y ago
This seems to be making the code less readable and more like javascript. I much prefer
public function getName(): string {
return $this->name;
}
over
public getName(): string => $this->name;
- munk-a 7y agoThe latter style doesn't (AFAICT) require single-lining, but setters and getters that do what would be naively assumed them to be do are a huge visual weight when in large volume. I am quite disappointed that less languages have tried novel solutions to that issue like C# has done with property declarations. Setters and getters can be valued for different reasons - I like them, personally, because it both allows you to separate the setting logic from the getting logic - it allows you to control and track reference acquisition (when that's important) and it allows you to easily swap in more complex logic for the simple expressions without requiring code changes to leak outside of the primary file. As such I've always loved language features and tricks to avoid ever actually defining getters and setters unless I need to explicitly override that behavior - and PHP has some neat tools in this space with `__get` and `__set` magic methods.