Topic: Function receive variable number of arguments - pass them to another

I'm trying to streamline my Xajax "handler" function... and thought this would be fantastic:

class Ajax
{
    function action($module)
    {
        $objResponse = new xajaxResponse();
        
        $handler = new {$module."Handler"}();
        
        $handler->action(      );
        
        return $objResponse;
    }
}

I know about the function handling functions in PHP (func_get_arg, etc...) so anyone know a way to take all the args from the function, and pass them to another function but not in an array?

Something like....

class Ajax
{
    function action($module)
    {
        $objResponse = new xajaxResponse();
        
        $handler = new {$module."Handler"}();

        /* I know what below doesn't actually work */

        $args = func_get_args();
        for($i = 0; $args[$i];$i++)
            if($i > 0)
                $pass[] = $args[$i];
        
        $handler->action( { explode(", ", $pass)} );
        
        return $objResponse;
    }
}

This way the function takes the function args and passes them on to an instantiated "module" but skips the module type.

Re: Function receive variable number of arguments - pass them to another

How about

$handler->action(implode(',',array_slice(func_get_args,1)));

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Function receive variable number of arguments - pass them to another

I've actually got something like this going...

function action()
{
    global $objResponse;
    $objResponse = new xajaxResponse();
    $handler = new func_get_arg(0);
    call_user_func_array(array($handler, "action"), array_slice(func_get_args(), 1));
    return $objResponse;
}

But I'm running into a wall with object scope. I'm getting an error in $handler about using $this when its not in a object scope.

Re: Function receive variable number of arguments - pass them to another

Here's what I ended up with.

Action is for onClick type of stuff, Form is for form processing. Form takes two args, The handler name and the output from xajax.processFormValues. Action can take infinite arguments and pass them to the handler.

function action()
{
    
    global $objResponse;
    $objResponse = new xajaxResponse();
    $handler_name = func_get_arg(0);
    $handler = new $handler_name;
    call_user_func_array(array($handler, "action"), array_slice(func_get_args(), 1));
    return $objResponse;
}
function form()
{
    global $objResponse;
    $objResponse = new xajaxResponse();
    $handlerName = func_get_arg(0);
    $handler = new $handlerName;
    $handler->form(func_get_arg(1));
    return $objResponse;
}

P.S. Would this be hard to make in Zend Framework? haha. This is the basis of my counter-proposal for ZF.