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
?>
کلاس ReflectionParameter
Introduction
کلاس ReflectionParameter اطلاعاتی درباره پارامترهای متد یا تابع باز میگرداند.
برای بررسی پارامترهای تابع ابتدا یک نمونه از ReflectionFunction یا ReflectionMethod بسازید و از ReflectionFunctionAbstract::getParameters() آنها برای دستیابی به آرایه پارامترها بهره برید.
Class synopsis
Properties
- name
-
Prop description
Table of Contents
- ReflectionParameter::allowsNull — بررسی مجاز بودن null
- ReflectionParameter::__clone — Clone
- ReflectionParameter::__construct — ساخت
- ReflectionParameter::export — ارسال
- ReflectionParameter::getClass — دریافت کلاس
- ReflectionParameter::getDeclaringClass — دریافت اعلام کلاس
- ReflectionParameter::getDeclaringFunction — دریافت اعلام تابع
- ReflectionParameter::getDefaultValue — دریافت مقدار پیشفرص پارامتر
- ReflectionParameter::getName — دریافت نام پارامتر
- ReflectionParameter::getPosition — دریافت موقعیت پارامتر
- ReflectionParameter::isArray — بررسی نیاز پارامتر به آرایه
- ReflectionParameter::isDefaultValueAvailable — بررسی مقدار پیشفرض موجود
- ReflectionParameter::isOptional — بررسی اختیاری بودن
- ReflectionParameter::isPassedByReference — بررسی ارسال با استفاده از ارجاع
- ReflectionParameter::__toString — به رشته
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"
