is it possible to alias a function with a different name in PHP? if yes how ?
suppose we have this function sleep();
is there any quick way to make an alias called wait();
without writing this code
function wait ($seconds)  {
    sleep($seconds);
}
is it possible to alias a function with a different name in PHP? if yes how ?
suppose we have this function sleep();
is there any quick way to make an alias called wait();
without writing this code
function wait ($seconds)  {
    sleep($seconds);
}
No, there's no quick way to do so - at least for anything before PHP v5.3, and it's not a particularly good idea to do so either. It simply complicates matters.
No, functions aren't 1st-class citizens so there's no wait = sleep like Javascript for example.  You basically have to do what you put in your question:
function wait ($seconds) { sleep($seconds); }
No, there's no quick way to do this in PHP. The language does not offer the ability to alias functions without writing a wrapper function.
If you really really really needed this, you could write a PHP extension that would do this for you. However, to use the extension you'd need to compile your extension and configure PHP to us this extension, which means the portability of your application would be greatly reduced.
Nope, but you can do this:
$wait = 'sleep';
$wait($seconds);
This way you also resolve arguments-number-issues
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());
}
You can look at lambdas also if you have PHP 5.3
$wait = function($v) { return sleep($v); };
you can use runkit extension
http://us.php.net/manual/en/function.runkit-function-copy.php
If you aren't concerned with using PHP's "eval" instruction (which a lot of folks have a real problem with, but I do not), then you can use something like this:
function func_alias($target, $original) {
    eval("function $target() { \$args = func_get_args(); return call_user_func_array('$original', \$args); }");
}
I used it in some simple tests, and it seemed to work fairly well. Here is an example:
function hello($recipient) {
    echo "Hello, $recipient\n";
}
function helloMars() {
    hello('Mars');
}
func_alias('greeting', 'hello');
func_alias('greetingMars', 'helloMars');
greeting('World');
greetingMars();