时间:2021-07-01 10:21:17 帮助过:16人阅读
class Person{ public $sex = '男'; function __construct() { echo 'parent __construct'; } } class Student extends Person{ private $id; private $name; private $age; //构造函数 function __construct($id,$name,$age) { parent::__construct(); echo '__construct'; $this->id = $id; $this->name = $name; $this->age = $age; } public function getName() { return $this->name; } //析构函数 function __destruct(){ echo '__destruct'; } } $su = new Student('id001','张三',20); echo $su->getName(); echo $su->sex;
打印结果:
parent __construct
__construct
张三
男
__destruct