我是php的初学者。所以我不明白为什么要提供此错误消息? 请帮我。这是我在本网站的第一个问题。
<?php
class shatil{
var $sat;
function __construct($my_name){//this is built in construct function
$this->sat = $my_name;
}
function set_sat($me_shatil){
$this->sat = $me_shatil;//you can Placement anything without'sat'
}
function get_sat(){
return $this->sat;
}
}
?>
<?php
$me = new shatil();
$i = new shatil();
$me->set_sat("Muhammad Mohoshin");
$i->set_sat("Habib Shatil");
echo "My middle Name ".$me->get_sat();
echo "<br/>";
echo "My first & last Name ".$i->get_sat();
echo "<br/>";
echo "My Full Name : ".$me->sat." ".$i->sat;
echo "<br/>";
$mamun = new shatil("my name is mamun");
echo $mamun->get_sat();
?>
答案 0 :(得分:2)
这是因为您没有将任何参数传递给构造函数
IT应该是:
$me = new shatil('name');
$i = new shatil('name2');
而不是:
$me = new shatil();
$i = new shatil();