PHP Australia Conference 2015

ReflectionFunction 类

(PHP 5)

简介

ReflectionFunction 类报告了一个函数的有关信息。

类摘要

ReflectionFunction extends ReflectionFunctionAbstract implements Reflector {
/* 常量 */
const integer IS_DEPRECATED = 262144 ;
/* 属性 */
public $name ;
/* 方法 */
public __construct ( mixed $name )
public static string export ( string $name [, string $return ] )
public Closure getClosure ( void )
public mixed invoke ([ mixed $parameter [, mixed $... ]] )
public mixed invokeArgs ( array $args )
public bool isDisabled ( void )
public string __toString ( void )
/* 继承的方法 */
final private void ReflectionFunctionAbstract::__clone ( void )
public ReflectionClass ReflectionFunctionAbstract::getClosureScopeClass ( void )
public ReflectionExtension ReflectionFunctionAbstract::getExtension ( void )
public string ReflectionFunctionAbstract::getName ( void )
abstract public void ReflectionFunctionAbstract::__toString ( void )
}

属性

name

函数的名称。只读,并在尝试赋值的时候会抛出 ReflectionException

预定义常量

ReflectionFunction 修饰符

ReflectionFunction::IS_DEPRECATED

指示了不建议使用的函数。

Table of Contents

add a note add a note

User Contributed Notes 1 note

up
0
Lorenz R.S.
3 years ago
Here is a concise example of ReflectionFunction usage for Parameter Reflection / introspection (e.g. to automatically generate API descriptions)

<?php
$properties
= $reflector->getProperties();
$refFunc = new ReflectionFunction('preg_replace');
foreach(
$refFunc->getParameters() as $param ){
   
//invokes ■ReflectionParameter::__toString
   
print $param;
}
?>

prints:

Parameter #0 [ <required> $regex ]
Parameter #1 [ <required> $replace ]
Parameter #2 [ <required> $subject ]
Parameter #3 [ <optional> $limit ]
Parameter #4 [ <optional> &$count ]
To Top