If you ever need to get the type hint of a parameter in a method use this.
<?php
//Target our class
$reflector = new ReflectionClass('MyClass');
//Get the parameters of a method
$parameters = $reflector->getMethod('FireCannon')->getParameters();
//Loop through each parameter and get the type
foreach($parameters as $param)
{
//Before you call getClass() that class must be defined!
echo $param->getClass()->name;
}
?>
PHP.mk документација
ReflectionClass::getMethod
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
reflectionclass.getmethod.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
reflectionclass.getmethod.php
ReflectionClass::getMethod
Референца за `reflectionclass.getmethod.php` со подобрена типографија и навигација.
ReflectionClass::getMethod
класата mysqli_driver
ReflectionClass::getMethod — Добива еден ReflectionMethod за метод на класа
= NULL
Добива еден ReflectionMethod за метод на класа.
Параметри
name-
Името на методот за рефлексија.
Вратени вредности
Errors/Exceptions
А ReflectionException ако методот не постои.
Примери
Пример #1 Основна употреба на ReflectionClass::getMethod()
<?php
$class = new ReflectionClass('ReflectionClass');
$method = $class->getMethod('getMethod');
var_dump($method);
?>Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред
object(ReflectionMethod)#2 (2) {
["name"]=>
string(9) "getMethod"
["class"]=>
string(15) "ReflectionClass"
}
Белешки од корисници 2 забелешки
Јарод Нетлс ¶
пред 15 години
sagittaracc на gmail точка ком ¶
пред 4 години
if you ever need to get the body of a method, use this extension (https://github.com/sagittaracc/reflection):
namespace sagittaracc\classes;
class Test
{
public function method()
{
if (true) {
return 'this method';
}
return 'never goes here';
}
}
$reflection = new ReflectionClass(Test::class);
$method = $reflection->getMethod('method');
echo $method->body; // if (true) { return 'this method'; } return 'never goes here';