Search code examples
phpargumentsforwarding

Argument Forwarding in PHP


Consider the following functions:

function debug() {
  $args = func_get_args();
  // process $args
}

function debug_die() {
  // call debug() with the passed arguments
  die;
}

The method debug_die exits after calling debug that takes a variable number of arguments.

So the arguments passed to debug_die as such are meant for debug only and just have to be forwarded. How can this be done in the debug_die method?


Solution

  • function debug_die() {
        call_user_func_array("debug", func_get_args());
        die;
    }