dongpa5277 2016-09-12 22:29
浏览 39

Child类中不存在PHP错误方法,method_exists($ child,$ method)传递

working with Laravel 5.1 here. I have created two classes, one extending the other:

abstract class ActivityTimeline extends Model

Which has:

$this->fields = [
   'owner_id',
   'contact_name',
   'mailing_label',
   'source_id',
   'source_raw',
   'initial_referer_raw',
   'primary_person',
   'connections',
];
foreach ($this->fields as $field) {
    if (method_exists($this, $field)) {
        dd('the method exists', $this, $field);
        $timelineActivity[$field] = $this->{$field}();
    }
}

And

class ContactActivity extends ActivityTimeline {

Which has:

public function primary_person()
{
    return $this->getPrimaryPerson($this->record);
}

The "dd('the method exists', $this, $field);" returns the following:

"the method exists"

ContactActivity {#963 ▶}

"primary_person"

However when this if statement passes, and I attempt to call the method that I just checked the existence of, I get:

BadMethodCallException in Builder.php line 2123: Call to undefined method Illuminate\Database\Query\Builder::primary_person()

So it seems that I'm not working with a ContactActivity object here, even though the dd shows that I am. Anyone know what I'm doing wrong here to get the wrong object?

  • 写回答

1条回答 默认 最新

  • dongxian6741 2016-09-12 22:38
    关注

    I think it's because you call a child method from the parent class. Try to add

    abstract function primary_person();
    

    On ActivityTimeline class

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)