<?php
header("content-type:text/html;charset=utf-8");
//函数重载
//子类中重载父类的方法
//1,在子类里面允许重写==覆盖父类的方法
//2,在子类中,使用parent访问父类中的被覆盖的属性和方法
//parent::__construct();
//parent::fun();
class Person{
public $name;
public $age;
public function hao(){
echo "我是".$this->name."性别".$this->age."<hr/>";
}
function __construct($name,$age){
$this->name=$name;
$this->age=$age;
}
}
class student extends Person{
function __construct($name,$age){
//将父类的方法的方法体来构造使用
parent::__construct($name,$age);
}
//将父类的方法覆盖重写
public function hao(){
//将父类的hao方法继承并使用
parent::hao();
}
}
$p=new Person("zhenyu","nv");
$p->hao();
echo "<hr/>";
$p=new student("xiaoyu","nan");
$p->hao();
输出:我是zhenyu性别nv我是xiaoyu性别nan