PHP:获取参数的数量 [英] PHP: Get argument count

查看:177
本文介绍了PHP:获取参数的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是令人难以置信的令人惊讶地看到,PHP没有的明显的功能做什么我要找的,所以我会在这里问。

This was incredibly surprising to see that PHP has no obvious function to do what I'm looking for, so I'll ask here.

你会如何去获得的参数个数一个特定函数的之外的功能(就像 func_num_args 仅从的功能)。

How would you go about getting the number of arguments a particular function has outside of the function (just like func_num_args only from outside the function).

该解决方案不能真正执行功能(即会被打败的目的),我想这样做(preferably)没有任何类型反射类的。

The solution can't actually execute the function (that would be defeating the purpose), and I'd like to do it (preferably) without any sort of reflection class.

可能?

推荐答案

呵呵,你可以使用的 ReflectionFunction 类,它的 ReflectionFunctionAbstract ,它定义了 getNumberOfParameters 功能:

Oh, you can use the ReflectionFunction class, which inherits from ReflectionFunctionAbstract, which defines the getNumberOfParameters function:

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

注意:这将只对用户职能的工作,而不是类或实例功能

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

这篇关于PHP:获取参数的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆