php8.5
Home/ Manual/ reflection / reflectionclass/ ReflectionClass::getMethod

ReflectionClass::getMethod

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Gets a ReflectionMethod for a class method

Description

ReflectionClass::getMethod(string $name): ReflectionMethod

Gets a ReflectionMethod for a class method.

Parameters

name

The method name to reflect.

Return Values

A ReflectionMethod.

Errors/Exceptions

A ReflectionException if the method does not exist.

Examples

Basic usage of ReflectionClass::getMethod

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

The above example will output:

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

See Also

  • ReflectionClass::getMethods

Source: reference/reflection/reflectionclass/getmethod.xml · from the official PHP manual (php/doc-en)