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

前端 未结 4 1245
孤独总比滥情好
孤独总比滥情好 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:35

    class base_class {
      function do_something() {
        print "base_class::do_something()\n";
      }
      function inherit_this() {
       //parent::do_something();
         $class = get_called_class();
         $class::do_something();
      }
    }
    

提交回复
热议问题