How do I call PHP parent methods from within an inherited method?

前端 未结 4 1250
孤独总比滥情好
孤独总比滥情好 2020-12-18 10:17

In PHP, I\'m trying to reference a method defined in an object\'s parent class, from a method inherited from the object\'s parent class. Here\'s the code:

c         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 10:46

    Im not quite sure I understands why you want to do like this. But I guess you cannot do it. I understand that you will be able to make a middle_class2 and be able inherit from that, and then it would be middle_class2 instead of middle_class's dosomething you call?!

    So I guess you'll need to create the

      function inherit_this() {
        parent::do_something();
      }
    

    in the middle_class.

    I thought about a get_class($this)::parent::do_something().. but that didn't work.

    Just to be sure.. You want to call middle_class::do_something() right??

提交回复
热议问题