问题描述
如何编写一个可以接受无限个参数的函数?
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:
$stmt->bind_param('sssd', $code, $language, $official, $percent);
推荐答案
以上建议都不错,但我认为它们不适合您的情况.
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);
如果要包装此函数,则需要将 references 传递给 bind_param 函数的原始参数变量.我不认为 func_get_args() 给你这个,而是给你价值.因此,不可能使用这些传递给父函数.我在尝试扩展 mysqli_stmt 时遇到了类似的问题,但从未得到令人满意的解决方案.
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.
这篇关于参数数量不限的 PHP 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!