ReflectionClass::getMethod

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getMethod獲取一個(gè)類方法的 ReflectionMethod

說明

public ReflectionClass::getMethod(string $name): ReflectionMethod

獲取一個(gè)類方法的 ReflectionMethod。

參數(shù)

name

要反射的方法名稱。

返回值

一個(gè) ReflectionMethod。

錯(cuò)誤/異常

如果方法不存在則會(huì)拋出 ReflectionException 異常。

范例

示例 #1 ReflectionClass::getMethod() 的基本用法

<?php
$class 
= new ReflectionClass('ReflectionClass');
$method $class->getMethod('getMethod');
var_dump($method);
?>

以上例程會(huì)輸出:

object(ReflectionMethod)#2 (2) {
  ["name"]=>
  string(9) "getMethod"
  ["class"]=>
  string(15) "ReflectionClass"
}

參見