php调用父类的构造函数

一 代码

<?php
class MyClass    //父类
{
    public function __construct()    //父类构造函数
	{
	    echo "父类的构造函数";
	}
}
class ChildClass extends MyClass     //子类 
{
    public function __construct()    //子类构造函数
	{
        echo "子类的构造函数"."<br>";
        parent::__construct();    //调用父类构造函数
    }		
}
$childClass = new ChildClass();    //对类的实例化
?>

 

二 运行结果
子类的构造函数
父类的构造函数
 

猜你喜欢

转载自cakin24.iteye.com/blog/2376973