In the following code I call a class with call_user_func()
.
if(file_exists('controller/' . $this->controller . '.controller.php')) {
require('controller/' . $this->controller . '.controller.php');
call_user_func(array($this->controller, $this->view));
} else {
echo 'error: controller not exists <br/>'. 'controller/' . $this->controller . '.controller.php';
}
Let’s say that the controller has the following code.
class test {
static function test_function() {
echo 'test';
}
}
When I call call_user_func('test', 'test_function')
there isn't any problem. But when I call a function that does not exist, it does not work. Now I want to check first if the function in the class test
does exist, before I call the function call_user_func
.
Is there a function that checks if a function exists in an class or is there another way I can check this?