Variable Functions w/ Unknown number of arguements

    Date: 11/30/07 (PHP Community)    Keywords: no keywords

    Suppose you have a function called like this:

    $obj = new $class();
    $obj->$function();

    Now suppose you want to pass the function a number of parameters from 0 to n inclusive. Is it possible to pass the function an unknown number of parameters, provided that the parameters are stored in array, where array[0] is the first parameter, array[1] is the second, and so on?

    EDIT: Solved

    There's a function call_user_func_array that allows you to call a variable function with an array for parameters. Unfortunately, it doesn't work on $obj->$function.

    However, for some reason (couldn't find the explination), setting the object and function in an array as the first parameter works.

    call_user_func_array(array($obj, $function), $args);

    Source: http://community.livejournal.com/php/600798.html

« preg_replace quandry || Optimise me! »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home