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
?>
La clase ReflectionParameter
(PHP 5)
Introducción
La clase ReflectionParameter recupera información sobre los parámetros de la función o del método.
Para hacer la introspección a los parámetros de la función, primero se crea una instancia de ReflectionFunction o de ReflectionMethod, y entonces se utiliza su método ReflectionFunctionAbstract::getParameters() para obtener un array de los parámetros.
Sinopsis de la Clase
Propiedades
- name
-
Nombre de el parámetro. De sólo lectura, lanza una ReflectionException en el intento de escribir.
Tabla de contenidos
- ReflectionParameter::allowsNull — Comprueba si null es permitido
- ReflectionParameter::canBePassedByValue — Devuelve si este parámetro de puede pasar por valor
- ReflectionParameter::__clone — Clon
- ReflectionParameter::__construct — Construct
- ReflectionParameter::export — Exportar
- ReflectionParameter::getClass — Obtener clase
- ReflectionParameter::getDeclaringClass — Obtiene declaración de la clase
- ReflectionParameter::getDeclaringFunction — Obtiene declaración de función
- ReflectionParameter::getDefaultValue — Obtiene el valor por omisión del parámetro
- ReflectionParameter::getDefaultValueConstantName — Returns the default value's constant name if default value is constant or null
- ReflectionParameter::getName — Obtener el nombre del parámetro
- ReflectionParameter::getPosition — Obtiene la posición del parámetro
- ReflectionParameter::isArray — Comprueba si el parámetro espera un array
- ReflectionParameter::isCallable — Returns whether parameter MUST be callable
- ReflectionParameter::isDefaultValueAvailable — Comprueba si el valor por omisión está disponible
- ReflectionParameter::isDefaultValueConstant — Returns whether the default value of this parameter is constant
- ReflectionParameter::isOptional — Comprueba si es opcional
- ReflectionParameter::isPassedByReference — Comprueba si es pasado por referencia
- ReflectionParameter::__toString — A string
fgm at riff dot org ¶
5 years ago
killgecNOFSPAM at gmail dot com ¶
5 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 ¶
5 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 getDefaultValue on Parameters will result in Exception "Cannot determine default value for internal functions"
