class Person {
public $name;
private $age; //private access
}
class Employee extends Person{
public $id;
public $salary; //class property
}
$emp = new Employee();
$emp->name="ABCD";
$emp->age = 30;
$emp->id=101;
$emp->salary=20000;
echo "<br/> Name : ".$emp->name;
echo "<br/> Age : ".$emp->age;
In this code, the child class variable $emp
can access private member of parent class Person
directly. Is this not the violation of private access rule?
It gives error when using a parent class variable, but works with child class variable!! Can anyone explain why?