【问题标题】:php one function alias of another function - how to pass variables throughphp 另一个函数的一个函数别名 - 如何传递变量
【发布时间】:2014-08-07 08:05:10
【问题描述】:

多年来,我的 PHP 函数(无论是在类中还是在类之外)都被设计为灵活并在同一个功能系列中完成多项任务。其中许多函数都简单地写成这样:

function myFunction(){
$args=func_get_args();
//work with arguments
}

底线:这些函数传递的参数数量不定。

我的问题是,如何为函数创建“别名”,但将参数传递给同名函数?

附:我可以使用一系列默认的 null 参数或使用 eval() 来开发 hack,但如果知道是否有比这更好的方法,我将不胜感激。谢谢!

【问题讨论】:

    标签: php function


    【解决方案1】:

    试试call_user_func_array:

    function myFunction(){
        $args = func_get_args();
        call_user_func_array('otherFunction', $args);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      相关资源
      最近更新 更多