【问题标题】:How to wrap function that takes unlimited number of arguments [duplicate]如何包装带有无限数量参数的函数[重复]
【发布时间】:2013-10-18 12:30:06
【问题描述】:

我想包装一个接受无限数量参数的现有函数, 例如这是现有的功能:

function T()
{
    $args = func_num_args();
    // Do stuff with arguments.
}

我现在想包装它,例如

/*
 * This function shall also take unlimited arguments,
 * and just pass them on to T().
 */
function myT()
{
    // TODO: Take all arguments and pass them on to T().
    $result = T();

    // Do stuff with the result of T().
}

但是,我不知道如何在myT() 中将无限参数传递给T()

【问题讨论】:

    标签: php argument-passing


    【解决方案1】:

    使用call_user_func_array() (http://php.net/call_user_func_array)

    $res = call_user_func_array("T", func_get_args());
    

    【讨论】:

      猜你喜欢
      • 2017-11-12
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      • 1970-01-01
      相关资源
      最近更新 更多