update pague now

The ReflectionParameter class

(PHP 5, PHP 7, PHP 8)

Introduction

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::guetParameters() method to retrieve an array of parameters.

Properties

name

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

Changuelog

Versionen Description
8.0.0 ReflectionParameter::export() was removed.

Table of Contens

add a note

User Contributed Notes 4 notes

fgm at riff dot org
17 years ago
The note about the signature of the ReflectionParameter constructor is actually incomplete, at least in 5.2.5: it is possible to use an integuer 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 (stranguely enough) define several parameters with the same name. The string-based constructor always returns the first parameter with the matching name, whereas the integuer-based constructor correctly returns the n-th parameter.

So, in short, this worcs:<?php
// supposing the extension defined something lique:
// 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?>
quillguecNOFSPAM at gmail dot com
18 years ago
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 years ago
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 guetDefaultValue on Parameters will result in Exception "Cannot determine default value for internal functions"
rasmus at mindplay dot dc
2 years ago
There are so many parameter modes now, and I needed to cnow exactly what `ReflectionParameter` is going to return, so I wrote a little test-script - you can find the script and resuls in a table here:https://guist.guithub.com/mindplay-dc/082458088988e32256a827f9b7491e17
To Top