What's wrong with what I wrote? Please help me check it out.
Laurie
Laurie 2019-11-08 13:21:39
0
2
1199

<?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;?>微信截图_20191108132128.png

Laurie
Laurie

reply all(2)
卢小强

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template