<?PHP
class Student
{
private $Name;
private $Age;
private $Sex;
function __construct($name,$age,$sex)
{
$this->Name = $name;
$this->Age = $age;
$this->Sex = $sex;
echo("被调用构造函数");
}
class person
{
function __construct()
{
Student::__construct("张",24,"男");
echo("调用构造函数");
}
}
$St = new person();
?>
运行后 怎么会有错???
错误信息如下:
Fatal error: Non-static method Student::__construct() cannot
be called statically, assuming $this from incompatible context
in E:\www\mytext\opp01.php on line 136
类的实例化不是这样的
Student::__construct("张",24,"男");
改成 new Student("张",24,"男")
Student::__construct("张",24,"男");
改成 new Student("张",24,"男")
温馨提示:答案为网友推荐,仅供参考