且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP在创建新对象(对象的call_user_func_array)时传递参数

更新时间:2023-11-30 12:46:34

从PHP 5.6开始,您现在可以使用新的Argument Unpacking运算符(...)用单行代码来实现.

As of PHP 5.6, you can now achieve this with a single line of code by using the new Argument Unpacking operator (...).

这是一个简单的例子.

$className='Foo';
$args=['arg1','arg2','arg3'];

$newClassInstance=new $className(...$args);

请参见 PHP变长参数列表了解更多信息.