3 ms·
> why would you even consider using an explicit setName over __set ? • You don't put logic of all setters in one place. Although you could create some dispatch
by pornel 15y ago
> why would you even consider using an explicit setName over __set ?
• You don't put logic of all setters in one place. Although you could create some dispatcher in __set that looks up method for the setter and calls it, that's a bit of magic that may not be expected by someone using the class.
• You can control visibility and override setters using standard PHP syntax rather than custom code in __set()
• Inside the class and derived classes it's clear when `$this->foo` is direct access and when it's a setter, otherwise you need to be careful about property declarations and visibility.
• It's possible to pass extra optional arguments to the setter
(none of these points are particularly strong, but there are non-insane reasons to use setters)