PHP: argument counting

It was incredibly amazing to see that PHP does not have an obvious function to do what I am looking for, so I will ask here.

How would you like to get the number of arguments that a particular function has outside the function (the same as func_num_argsonce outside the function).

The solution cannot actually fulfill the function (which will defeat the goal), and I would like to do this (preferably) without any reflection class.

Possible?

+3
source share
1 answer

Oh, you can use a class ReflectionFunctionthat inherits from ReflectionFunctionAbstractthat defines a function getNumberOfParameters:

$func_reflection = new ReflectionFunction('function_name');
$num_of_params = $func_reflection->getNumberOfParameters();

Note. . This will only work with user functions, not class or instance functions.

+8
source

Source: https://habr.com/ru/post/1783141/


All Articles