I have a problem with a magic method __set() in an abstract class (Model), as i cant assign any property of the class that extend Model. Neither trying to print the name of the variable in the __set method:
abstract class Model
{
public $data;
public function __set($name, $value)
{
echo $name; $this->$name = $value;
}
}
class User extends Model
{
public $id;
}
$u = new User();
$u->data = "hello"; //print "data";
$u->id = 123; //print NOTHING.. WHY¿?
__setis called when you try to assign a value in undefined property. In your case__setwill never be called because both of the properties are defined and exists.See here the output is nothing for both of the properties and try with removing one of the property declaration part and see the output difference.