php方法未定义错误


php method undefined error

我有一个Model.class.php和一个Bag.class.php,Bag类扩展了Model类。

但是,当我尝试调用Bag.class.php中定义的函数时,它显示了一个致命错误"调用中的未定义函数fill_entiy()"

bag.class.php:

class Bag extends Model{
 public function __construct($table_name){
    $this->table_name = $table_name;
 }
 public function fill_entity($row){
     $this->id = $row['bagID'];
     $this->name = $row['bagName'];
     $this->price = $row['bagPrice'];
     $this->url = $row['bagURL'];
     $this->img_url = $row['bagImgURL'];
     $this->mall_id = $row['mallID'];
     $this->brand_id = $row['brandID'];
 }

这是我的php页面,我在这里调用这个函数:

$bag = new Bag($bagtype);
$bag.fill_entity($row);  <---- error on this line.

您使用了错误的语法。PHP不使用点表示法,而是使用->(箭头/指针表示法)

尝试使用这个:

$bag->fill_entity($row);

.仍在PHP中使用,但用于字符串串联。)

不要为错过这个而感到难过,当我第一次处理PHP时,我已经做了很多次了。

在PHP中,它应该是$bag->fill_entity($row);而不是$bag.fill_entity($row);