从数组_call() 函数$arg创建动态参数列表


Create dynamic argument list from _call() functions $arg array

我正在将一个php库升级到最新版本(有点重写),我遇到的一个问题是作者决定将他的所有功能都打包。他一直这样做,所以我想在继承的类中尝试这个技巧:

<?php
// this will extend animal..just demo code
class dog {
public function __call($method, $args) {
    // I have a function to camelcase this - only for developing
    $call_method = 'barkLoud';
    //this is so it doesn't blow up - this is what I'm trying to fix
    $myArgsList = 120;  
    $this->$call_method($myArgsList);
}   
function barkLoud($decibals)
{
    echo 'Barking at '. $decibals;
}
}
$poppy = new dog;
print $poppy->bar_loud(100);

我不明白该怎么做的是:会有可变数量的参数,变量类型(整数、字符串、数组、对象......

如何分解$args,使其正确构建参数列表,该参数列表将位于占位符现在的位置$myArgList?

(请记住,我的参数可能是数组或对象,所以请不要建议使用 implode() 构建字符串......还请记住,我根本不想更改新的库类)

蒂亚

使用return call_user_func_array(array($this,$call_method), $args);