The strange thing is that you have a setter, but leave the public property. (Assuming __get magic is missing.)
Usually you want to use getters / setters to gain more control over what can be assigned to a property and what cannot. Or you may want to execute code when accessing or changing a property. In any case, you should force the use of getters / setters by creating a private or protected property, otherwise this is pretty pointless. It is about discouraging oneself or others who will use the class from firing on their own leg.
If the installer in your example only sets the value without doing anything else, it is superfluous. If it does something else that is required for each value, you have a flaw in the design of your class, since you can change the value without using setter.
class Foo { public $bar = 0; // is only allowed to contain numeric values public function setBar($val) { if (is_numeric($val)) { $this->bar = $val; } } } $obj = new Foo(); $obj->bar = 'some value'; // set a string, which is not allowed
If you would make $bar protected , that would be impossible.
deceze
source share