Possible Duplicate:
Is it really that wrong not using setters and getters?
Why use getters and setters?
I have been always wondering why are people using getters/setters in PHP instead of using public properties?
From another question, I've copied this code:
<?php
class MyClass {
private $firstField;
private $secondField;
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}
}
public function __set($property, $value) {
if (property_exists($this, $property)) {
$this->$property = $value;
}
return $this;
}
}
?>
I see no difference between this and using public fields.
Well, I know it may help us to validate data in both getter and setter, but the example above just doesn't fit it