How to alias a function in PHP?

Atif Mohammed Ameenuddin picture Atif Mohammed Ameenuddin · Nov 6, 2009 · Viewed 42.8k times · Source

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 wait?

By now I'm doing like this:

function wait( $seconds ) {
    sleep($seconds);
}

Answer

Lukman picture Lukman · Nov 6, 2009

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());
}