时间:2021-07-01 10:21:17 帮助过:26人阅读
class Person{
public $name;
public $age;
function _construct($name,$age){
$this->name=$name;
$this->age=$age;
}
function say(){
echo "my name is".$this->name."my age is".$this->age."
";
}
}
$person1=new Person("jack","30");
$person1->say();
$person2=new Person("mike","25");
$person2->say();
PHP新手,学习到了面向对象来了,反反复复的检查了以上代码,没发觉有什么问题,可就是不能输出名字与年龄,访问范围好像也没超出啊。输出只显示 my name is my age is 。。求解答,感激不尽,如果有时间,恳请详细解答。
class Person{
public $name;
public $age;
function _construct($name,$age){
$this->name=$name;
$this->age=$age;
}
function say(){
echo "my name is".$this->name."my age is".$this->age."
";
}
}
$person1=new Person("jack","30");
$person1->say();
$person2=new Person("mike","25");
$person2->say();
PHP新手,学习到了面向对象来了,反反复复的检查了以上代码,没发觉有什么问题,可就是不能输出名字与年龄,访问范围好像也没超出啊。输出只显示 my name is my age is 。。求解答,感激不尽,如果有时间,恳请详细解答。
_construct --> __construct
构造方法的名字写错了,前面是2个dash
看来楼主还不懂什么是构造方法,看手册吧