[ACCEPTED]-Pass all arguments to another function-syntax

Accepted answer
Score: 25

How about using:

$args = func_get_args();
call_user_func_array('mysql_safe_query', $args);

0

Score: 16

N.B. In PHP 5.6 you can now do this:

function mysql_row_exists(...$args) {
    $result = mysql_safe_query(...$args);
    return mysql_num_rows($result) > 0;
}

Also, for 2 future readers, mysql_* is deprecated -- don't 1 use those functions.

Score: 0

Depending on the situation, following might 10 also work for you and might be a little 9 faster.

function  mysql_safe_query($format) {
    $args = func_get_args();
    $args = is_array($args[0]) ? $args[0] : $args; // remove extra container, if needed
    // ...

Which now allows for both types of 8 calling, but might be problematic if your 7 first value is supposed to be an actual array, because it 6 would be unpacked either way.

You could additionally 5 check on the length of your root-array, so 4 it might not be unpacked if if there are 3 other elements, but as mentioned: It is 2 not really that "clean" in general, but 1 might be helpful and fast :-)

More Related questions