When I try to Override the class variable same way as override the class method in PHP. Like:
class DataMapper {
protected $_name = null;
public function printName() {
echo $this->_name;
}
}
class Model extends DataMapper {
protected $_name = 'Ana';
}
$test = new Model();
$test->printName();
It's print 'Ana'.
Why PHP can do such a thing like that ? It break the law of object oriented paradigm
static), they are object/instance variables. As people explain, this is how inheritance is supposed to work with protected members. If you were instead to set a private class variable (i.e.private static $myVar = 'Ana';) then it would not be defined in any child class.