Check if method exists in the same class

后端 未结 4 766
闹比i
闹比i 2020-12-06 09:18

So, method_exists() requires an object to see if a method exists. But I want to know if a method exists from within the same class.

I have a method that

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 10:03

    The best way in my opinion is to use __call magic method.

    public function __call($name, $arguments)
    {
        throw new Exception("Method {$name} is not supported.");
    }
    

    Yes, you can use method_exists($this ...) but this is the internal PHP way.

提交回复
热议问题