如何动态检查PHP中函数的参数数量 [英] how to dynamically check number of arguments of a function in php

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

问题描述

如何在运行时首页检查PHP中方法或函数具有的许多参数.

how can I check at runtime home many parameters a method or a function have in PHP.

示例


class foo {
   function bar ( arg1, arg2 ){
    .....
   }
}

我将需要知道是否可以运行类似的东西

I will need to know if there is a way to run something like


get_func_arg_number ( "foo", "bar" )

结果为


2

推荐答案

您需要使用 reflection 进行做到这一点.

You need to use reflection to do that.

$method = new ReflectionMethod('foo', 'bar');
$num = $method->getNumberOfParameters();

这篇关于如何动态检查PHP中函数的参数数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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