<?phpclass Staff{ private $name; private $age; private $salary; public function _construct($name,$age,$salary) { $this->name=$name; $this->age=$age; $this->salary=$salary; } public function _get($name) { return $this->$name; }}$obj=new Staff('peter',18,4000);echo $obj->name;echo $obj->age;?>
If you want to output $name, you must use the public function _get method. Private is a private variable and cannot be called externally.
The properties in the Staff class are defined as private and can only be called within the class. Change them to public and solve the problem