PHP function with unlimited number of parameters

后端 未结 8 1760
执念已碎
执念已碎 2020-12-03 13:45

How do I write a function that can accept unlimited number of parameters?

What am trying to do is create a function within a class that wraps the following:

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 14:33

    The above suggests are all good, but I don't think they will be suitable for your situation.

    $stmt->bind_param('sssd', $code, $language, $official, $percent);
    

    If you want to wrap this function, you will need to pass references to the original argument variables to the bind_param function. I don't think func_get_args() gives you this, it gives you values instead. Thus it won't be possible to use these to pass to the parent function. I battled with a similar issue when trying to extend mysqli_stmt and never came to satisfactory solution.

    This is not really an answer to your question I'm afraid, just a warning that other arguments may not work in your particular application of arbitrary number of arguments.

提交回复
热议问题