您好,欢迎访问一九零五行业门户网

php __callStatic方法参数的一个问题

看下面的代码
php
class xxoo{ private static $instance; public function func($arg1, $arg2, $arg3, $arg4) { } public static function __callstatic($method, $arguments) { if (!self::$instance) { self::$instance = new self(); } return self::$instance->$method($arguments); }}xxoo::func('arg', 'arg2', array('name'), 'sf');

__callstatic实现静态方法调用实例方法,但是$arguments变量是一个数组,在不改变func方法(参数可能不固定)的前提下如何实现对实例方法传参.
回复内容: 看下面的代码
php
class xxoo{ private static $instance; public function func($arg1, $arg2, $arg3, $arg4) { } public static function __callstatic($method, $arguments) { if (!self::$instance) { self::$instance = new self(); } return self::$instance->$method($arguments); }}xxoo::func('arg', 'arg2', array('name'), 'sf');

__callstatic实现静态方法调用实例方法,但是$arguments变量是一个数组,在不改变func方法(参数可能不固定)的前提下如何实现对实例方法传参.
call_user_func_array([self::$instance, $method], $arguments);
其它类似信息

推荐信息