您好,欢迎访问一九零五行业门户网

php类没输出内容

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
看来楼主还不懂什么是构造方法,看手册吧
其它类似信息

推荐信息