PHP构造函数 在一个类中调用另一类的构造函数怎么会出错???????
<?PHPclassStudent{private$Name;private$Age;private$Sex;function__construct($name,$age...
<?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 展开
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 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询