<?php
//人类
class person{
protected $name;
protected $age;
protected $sex;
function __construct($name,$age,$sex){
$this->name = $name;
$this->age = $age;
$this->sex = $sex;
}
function say(){
echo "无聊的人";
}
}
$p=new person();
$p->say();
?>
但最后显示有个错误
Warning: Missing argument 1 for person::__construct(), called in G:\www\1.php on line 17 and defined in G:\www\1.php on line 7Warning: Missing argument 2 for person::__construct(), called in G:\www\1.php on line 17 and defined in G:\www\1.php on line 7Warning: Missing argument 3 for person::__construct(), called in G:\www\1.php on line 17 and defined in G:\www\1.php on line 7
求解
//人类
class person{
protected $name;
protected $age;
protected $sex;
function __construct($name,$age,$sex){
$this->name = $name;
$this->age = $age;
$this->sex = $sex;
}
function say(){
echo "无聊的人";
}
}
$p=new person();
$p->say();
?>
但最后显示有个错误
Warning: Missing argument 1 for person::__construct(), called in G:\www\1.php on line 17 and defined in G:\www\1.php on line 7Warning: Missing argument 2 for person::__construct(), called in G:\www\1.php on line 17 and defined in G:\www\1.php on line 7Warning: Missing argument 3 for person::__construct(), called in G:\www\1.php on line 17 and defined in G:\www\1.php on line 7
求解
$p=new person($name,$age,$sex);
$p->say();
$this->name = $name;
$this->age = $age;
$this->sex = $sex;
}