检查特定文件中是否存在函数?

时间:2016-12-07 21:50:15

标签: php

我想在调用之前检查$this->_controller函数foo是否存在。

通话示例:

call_user_func_array([$this->_controller, $this->_url[1]]);

这将调用插入URL中的控制器中的函数url[1],基本上是:

webserver/backend/foo

我想检查foo是否确实存在于后端。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

大多数事情都有功能。检查method_exists()

if(method_exists($this->_controller, $this->_url[1])) {
    call_user_func_array([$this->_controller, $this->_url[1]]);
}

其他用途请参阅is_callable()

相关问题