(PHP 4, PHP 5, PHP 7, PHP 8)
func_num_args — Returns the number of arguments passed to the function
Gets the number of arguments passed to the function.
This function may be used in conjunction with func_get_arg() and func_get_args() to allow user-defined functions to accept variable-length argument lists.
У цієї функції немає параметрів.
Returns the number of arguments passed into the current user-defined function.
Generates a warning if called from outside of a user-defined function.
Приклад #1 func_num_args() example
<?php
function foo()
{
echo "Number of arguments: ", func_num_args(), PHP_EOL;
}
foo(1, 2, 3);
?>
Поданий вище приклад виведе:
Number of arguments: 3
Зауваження:
Починаючи з PHP 8.0.0, сімейство функцій func_*() стало більш прозорим щодо названих параметрів, обробляючи їх так, ніби всі передані позиційно, а пропущеним аргументам призначаються стандартні значення. Ця функція ігнорує набір невідомих названих варіативних параметрів. Набір невідомих названих параметрів доступний через варіативний параметр.
...
syntax