If I understand correctly, with __set() you can create class variables on the fly, which will be public, as well as access private/protected properties.
It seems like using:
__set($name,$value) {
$this->data[$name] = $value;
}
OR:
__set($name,$value) {
$this->$name = $value;
}
... would both result in all kinds of garbage in and out.
With individual setters (mutators), 1 for each protected/private property, you have individual validation control, but you have to write a bunch of setters.
Is there some way to take advantage of magic __set() and still validate depending on the property.
E.g. let's say
class stuff {
private $name; // alphabet, limit 10 chars
private $size; // integers 1 - 10;
private $price; // decimals 0.000 - 999.999
__set($property,$value) {
$this->$property = $value;
}
}
$thing = new stuff();
$thing->name = 1234;
$thing->size = 'b';
$thing->price = -40;
How would you validate the bad assignments?