略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionFunctionAbstract::getNumberOfParameters

2024-12-23

ReflectionFunctionAbstract::getNumberOfParameters

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

ReflectionFunctionAbstract::getNumberOfParameters获取参数数目

说明

public ReflectionFunctionAbstract::getNumberOfParameters(): int

获取函数定义的参数数目,包括可选参数

警告

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

参数的个数

参见

add a noteadd a note

User Contributed Notes 2 notes

up
5
Robert Pitt ( LitePHP )
12 years ago
Working on a new MVC Application Framework i use this method to check how many arguments are required before calling the sub method!

Example

<?php
        $this
->method_args_count = $this->CReflection
           
->getMethod($Route->getMethod())
            ->
getNumberOfParameters();
       
//Maybe be 5 but if uri is /controller/method/single_param/ we only of 1
       
$this->params = $Route->getParams(); //0 in some cases

       
if($this->method_args_count > count($this->params))
        {
           
$this->difference = ($this->method_args_count - count($this->params));
            for(
$i=0;$i<=$this->difference;$i++)
            {
               
$this->params[] = false;
            }
        }
       
       
//Call the method with correct amount of params
        // but as false for params that have not been passed!
       
call_user_func_array(array(new $this->obj,$Route->getMethod()),$this->params);
?>
up
0
8ctopus
1 year ago
$reflection = new ReflectionFunction('implode');
echo $reflection->getNumberOfParameters();

官方地址:https://www.php.net/manual/en/reflectionfunctionabstract.getnumberofparameters.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3