我想从A类中实现一个回调,它包括特定的方法作为参数。例如:
call_user_func_array($callback, ['$this->get', '$this->post']);
然而这并不起作用。我在这里的目标是做到这一点:
index.php
$API = new API();
$API->state('/users', function ($get, $post) {
$get('/', 'UserController.getAll');
});
API.php
public function state ($state, $callback) {
call_user_func_array($callback, ['$this->get', '$this->post']);
}
public method get ($uri, $ctrl) { echo 'getting'; }
public method post ($uri, $ctrl) { echo 'posting'; }
感谢您的任何输入!我知道使用 $this->method 是行不通的,因为在回调范围内,$this-> 不存在。