header("Content-Type:text/html;charset=utf-8");class Class1 extends Class2{ public static $a = 'Class1';}class Class2 extends Class3{ public static $a = 'Class2'; public function __construct(){ echo 'Class2'; }}class Class3{ public static $a = 'Class3'; public function __construct(){ echo 'Class3'; }}$obj = new Class1();
Class2 构造覆盖了Class3
Class2 构造里面加入 parent::__construct();
试试
这段代码运行出错
PHP Fatal error: Class 'Class2' not found
晕。顺序错了。
header("Content-Type:text/html;charset=utf-8");
class Class3 {
public static $a = 'Class3';
public function __construct() {
echo 'Class3';
}
}
class Class2 extends Class3 {
public static $a = 'Class2';
public function __construct() {
echo 'Class2';
}
}
class Class1 extends Class2 {
public static $a = 'Class1';
}
$obj = new Class1();
OK ,good, 以前搞JS的, js中函数预先定义,不问顺序