How to properly handle expected parameter errors encountered
P粉976737101
2023-08-16 17:36:54
<p><br /></p>
<pre class="brush:php;toolbar:false;">function calculate(){
echo "Number of parameters:" . func_get_args();
echo "The third parameter is:" . func_get_arg(3);
print_r(func_get_arg());
$result = 0;
foreach(func_get_arg() as $arg) :
$result = $arg;
end foreach;
echo $result;
calculate(10, 20, 30, 1502);</pre>
<p>How to solve this problem, I have a bad argument error in the variadic argument list of this function? </p>
Latest versions of PHP do not allow a mismatch between the function parameter list and the parameter list in the call. You can use ellipses in the argument list to allow unlimited arguments instead of calling
func_get_args()
.