class Perpon
{
private $Pid;
private $Pname;
private $Page;
private $Psex;
private $Pbirthday;
public function __construct($Pid,$Pname,$Page,$Psex,$Pbirthday)//PHP5中间的构造函数
{
$this->Pid=$Pid;
$this->Pname=$Pname;
$this->Page=$Page;
$this->Pbirthday=$Pbirthday;
echo "创建了一个对象"."<br>";
}
public function __set($name,$value)
{
$this->$name=$value;
}
function show(){
echo ("我的姓名:$this->Pname,我的年龄:$this->Page,我的性别是:$this->Psex,我的生日是$this->Pbirthday <br>");
}
public function __get($name)
{
return $name;
}
public function dining()
{
echo "$this->Pname 正在吃饭 <br>";
}
public function shuohua()
{
echo "$this->Pname喜欢说话 <br>";
}
public function gaosu()
{
echo "我的姓名叫做$this->Pname <br>";
}
public function IT()
{
echo "$this->Pname 的工作是IT行业 <br>";
}
}
class Student extends Perpon
{
public function __construct()//PHP5中间的构造函数
{
echo "子类的构造函数";
}
public function IT()//PHP5中间的构造函数
{
parent::IT();
echo "$this->Pname 的工作是学生<br>";
}
}
$perpon=new Perpon('1','zhangsan','18','男','9月23');
$perpon->show();
$perpon->dining();
$perpon->shuohua();
$perpon->gaosu();
$perpon->IT();
$student=new Student();
$student->IT();
?>
子类的IT方法调不到父类的Pname属性