See the following code {code ...} __callstatic implements static methods to call the instance method, but the $ arguments variable is an array. How to transmit parameters to the instance method without changing the func method (the parameters may not be fixed. see the following code.
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
Call the instance method using static methods,$arguments
Variable is an array without changingfunc
How to transmit parameters to the instance method on the premise that the method (parameters may not be fixed.
Reply content:
See the following code.
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
Call the instance method using static methods,$arguments
Variable is an array without changingfunc
How to transmit parameters to the instance method on the premise that the method (parameters may not be fixed.
call_user_func_array([self::$instance, $method], $arguments);