downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ReflectionParameter::allowsNull> <ReflectionObject::export
[edit] Last updated: Sat, 07 Jan 2012

view this page in

The ReflectionParameter class

(PHP 5)

소개

The ReflectionParameter class retrieves information about function's or method's parameters.

To introspect function parameters, first create an instance of the ReflectionFunction or ReflectionMethod classes and then use their ReflectionFunctionAbstract::getParameters() method to retrieve an array of parameters.

클래스 개요

ReflectionParameter implements Reflector {
/* 프로퍼티 */
/* 메소드 */
public bool ReflectionParameter::allowsNull ( void )
final private void ReflectionParameter::__clone ( void )
ReflectionParameter::__construct ( string $function , string $parameter )
public static string ReflectionParameter::export ( string $function , string $parameter [, bool $return ] )
public ReflectionClass ReflectionParameter::getClass ( void )
public ReflectionClass ReflectionParameter::getDeclaringClass ( void )
public ReflectionFunction ReflectionParameter::getDeclaringFunction ( void )
public string ReflectionParameter::getName ( void )
public bool ReflectionParameter::isArray ( void )
public bool ReflectionParameter::isOptional ( void )
public string ReflectionParameter::__toString ( void )
}

프로퍼티

name

Name of the parameter. Read-only, throws ReflectionException in attempt to write.

Table of Contents



ReflectionParameter::allowsNull> <ReflectionObject::export
[edit] Last updated: Sat, 07 Jan 2012
 
add a note add a note User Contributed Notes ReflectionParameter
fgm at riff dot org 11-May-2008 06:44
The note about the signature of the ReflectionParameter constructor is actually incomplete, at least in 5.2.5: it is possible to use an integer for the second parameter, and the constructor will use it to return the n-th parameter.

This allows you to obtain proper ReflectionParameter objects even when documenting code from extensions which (strangely enough) define several parameters with the same name. The string-based constructor always returns the first parameter with the matching name, whereas the integer-based constructor correctly returns the n-th parameter.

So, in short, this works:
<?php
// supposing the extension defined something like:
// Some_Class::someMethod($a, $x, $y, $x, $y)
$p = new ReflectionParameter(array('Some_Class', 'someMethod'), 4);
// returns the last parameter, whereas
$p = new ReflectionParameter(array('Some_Class', 'someMethod'), 'y');
// always returns the first $y at position 2
?>
killgecNOFSPAM at gmail dot com 24-Jul-2007 11:53
Signature of constructor of ReflectionParameter correctly is:

public function __construct(array/string $function, string $name);

where $function is either a name of a global function, or a class/method name pair.
massimo at mmware dot it 18-Jul-2007 02:58
I found these limitations using class ReflectionParameter from ReflectionFunction with INTERNAL FUNCTIONS (eg print_r, str_replace, ... ) :

1. parameter names don't match with manual: (try example 19.35 with arg "call_user_func" )
2. some functions (eg PCRE function, preg_match etc) have EMPTY parameter names
3. calling getDefaultValue on Parameters will result in Exception "Cannot determine default value for internal functions"

 
show source | credits | stats | sitemap | contact | advertising | mirror sites