PHP Variable Overriding

Viewed 27186

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

3 Answers
Related