How to alias a function in PHP?

前端 未结 15 1253
死守一世寂寞
死守一世寂寞 2020-11-30 00:13

Is it possible to alias a function with a different name in PHP? Suppose we have a function with the name sleep. Is there a way to make an alias called wa

15条回答
  •  余生分开走
    2020-11-30 00:49

    Until PHP 5.5

    yup, function wait ($seconds) { sleep($seconds); } is the way to go. But if you are worried about having to change wait() should you change the number of parameters for sleep() then you might want to do the following instead:

    function wait() { 
      return call_user_func_array("sleep", func_get_args());
    }
    

提交回复
热议问题