Is the magic method __set called when setting properties in __construct?
class MyClass
{
public function __construct()
{
$this->property = 'something';
}
public function __set($name,$value)
{
$this->{$name} = ($name == 'property')?'other value':$value;
}
}
This is perfectly legal to do. From the manual:
__set() is run when writing data to inaccessible properties.
It does not matter if it is done from the constructor.
so invoking:
$x = new MyClass();
var_dump($x);
will result in:
object(MyClass)#1 (1) { ["property"]=> string(11) "other value" }