Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 动态调用非静态方法_Php_Static_Callback - Fatal编程技术网

Php 动态调用非静态方法

Php 动态调用非静态方法,php,static,callback,Php,Static,Callback,我试着像这样调用非静态方法: call_user_func_array(array("Notifications", "getNots"), $params) {{ Notifications.getNotes(3) }} 我得到了一个错误: call_user_func()要求参数1是有效的回调非静态方法 功能是: class Notifications { public function getNots($limit, $test = 0) { } } 怎么办 实际上,

我试着像这样调用非静态方法:

call_user_func_array(array("Notifications", "getNots"), $params)
{{ Notifications.getNotes(3) }}
我得到了一个错误: call_user_func()要求参数1是有效的回调非静态方法

功能是:

class Notifications {
    public function getNots($limit, $test = 0) {
    }
}
怎么办

实际上,我试图构建一个函数,该函数获取html页面的html代码 并替换所有这样的文本:

call_user_func_array(array("Notifications", "getNots"), $params)
{{ Notifications.getNotes(3) }}
要返回方法


tnx很多

要使用非静态函数实现这一点,您需要实例化一个通知对象(如果没有完成,则将其作为回调数组中的第一个值传递到call_user_func_array()。类似于这样:

$notifications = new Notification();
call_user_func_array(array($notifications, "getNots"), $params);

如果已经实例化,则传递实例,而不是类名。

是否尝试过:$notifications=new notifications();call_user\u func_数组(array($notifications,“getNots”),$params));我从另一个对象获得了对象,如下所示:对象模板-->变量对象通知为什么使用
调用用户函数数组
?您必须询问原始海报。当我需要调用一组方法,并且调用的特定方法取决于之前的用户输入时,我会使用这个例子。在这种情况下,它可能比添加一个开关或一组if条件更简单。