美文网首页
在thinkphp使用call_user_func 回调函数的问

在thinkphp使用call_user_func 回调函数的问

作者: ambition_wy | 来源:发表于2018-01-23 17:43 被阅读0次

在thinkphp使用call_user_func 回调函数的时候会发现调用不了,网上查了好多资料都没有相关的问题,用了原生php做测试,call_user_func个人理解的大概原理是,他只能调用当前文件的方法,然后在tp框架里面是调用不了的,下面直接来代码:

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
        call_user_func_array(array(new IndexController(),'test'), []);
}

public function test(){
      echo 'test';
}

也就是在框架里面我们只能使用call_user_func_array(),要回调的函数必须要返回一个类给他
我这里是在同一个类里面的,所以就用new IndexController,如果是调用其他类的回调函数就实例化其他类名称

相关文章

网友评论

      本文标题:在thinkphp使用call_user_func 回调函数的问

      本文链接:https://www.haomeiwen.com/subject/zazsaxtx.html