Arity

Arity is the number of arguments, or operands, that a function, method, or operator accepts: a unary operator such as ! has arity 1, a binary operator such as + has arity 2, and a function’s arity is the count of its declared parameters. A function whose arity is fixed always expects exactly that many arguments; a function of variable arity, called variadic, accepts any number of arguments from a given point onward.

Arity matters for overload resolution in languages that dispatch on parameter count, for currying, where a function is considered fully applied only once it has received as many arguments as its arity, and for reflection, where a caller may need to discover how many arguments a callable expects before invoking it dynamically.

PHP supports both fixed and variable arity directly. A function’s fixed arity is simply its parameter list; variable arity is declared with the ... splat operator on the last parameter, and the actual number of arguments received by any call, fixed or variadic, can be inspected at runtime with func_num_args(), or discovered ahead of a call through ReflectionFunction::getNumberOfParameters().

<?php

    function sum(int ...$numbers): int {
        return array_sum($numbers);
    }

    sum(1, 2, 3); // called with arity 3, though sum() itself is variadic

    function greet(string $name) {
        echo func_num_args(); // 1: this call's actual arity
    }

?>

Documentation

See also 4.6 - Arity, partial application and currying.

Related : Variadic, func_get_args(), Functions, Currying, Overloading