<?php header("Content-type:text/html;charset=utf-8"); class family { public $name; public $age; public function __construct() { echo "父类构造函数<br>"; } public function say() { echo "父类" . $this->name . "今年," . $this->age; } } class sun extends family { public $name; //与父类属性同名将覆盖父类的name public $age; public function __construct() { parent::__construct(); echo "子类构造函数<br>"; } public function sayddd() { $this->name = "ddddd"; $this->age = 222; $this->say(); } } $sun = new sun(); $sun->sayddd();