文字

ReflectionFunctionAbstract::getParameters

(PHP 5)

ReflectionFunctionAbstract::getParameters获取参数

说明

public array ReflectionFunctionAbstract::getParameters ( void )

通过 ReflectionParameter 数组返回参数列表

Warning

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

参数

此函数没有参数。

返回值

一组 ReflectionParameter 对象表示每一参数

参见

  • ReflectionFunctionAbstract::getNumberOfParameters() - 获取参数数目
  • func_get_args() - 返回一个包含函数参数列表的数组

用户评论:

[#1] dabidi at slupca dot pl [2015-10-27 13:33:30]

This is part of my private framework that uses reflection. 
This function get arguments list from theme method and puts corresponding vars from $_REQUEST ($_GET, $_POST, and $_COOKIE)

<?php
public static function fire_theme_method($class$method)
{
        
$fire_args=array();
        
        
$reflection = new ReflectionMethod($class$method);

    foreach(
$reflection->getParameters() AS $arg)
    {
        if(
$_REQUEST[$arg->name])
        
$fire_args[$arg->name]=$_REQUEST[$arg->name];
        else
        
$fire_args[$arg->name]=null;
    }
        
    return 
call_user_func_array(array($class$method), $fire_args);
}
?>

For example, if my theme method needs only id, and we get this url:
http://example.com/my_class/my_method/?id=12&some_unwanted_var=123
will be ignored some_unwanted_var

Of course behind this i have .htaccess, autoloader and controller

上一篇: 下一篇: