Monday, October 6, 2025
HomeLanguagesPHP | ReflectionClass getMethod() Function

PHP | ReflectionClass getMethod() Function

The ReflectionClass::getMethod() function is an inbuilt function in PHP which is used to return a ReflectionMethod for the specified class method.

Syntax:

ReflectionMethod ReflectionClass::getMethod ( string $name )

Parameters: This function accepts a parameter $name which is the method name.

Return Value: This function returns a ReflectionMethod for the specified class method.

Below program illustrate the ReflectionClass::getMethod() function in PHP:




<?php
  
// Using ReflectionClass over the inbuilt class
// 'ReflectionClass'
$class = new ReflectionClass('ReflectionClass');
  
// Calling the getMethod over the method named
// as 'getMethod'
$method = $class->getMethod('getMethod');
  
// Getting the ReflectionMethod for the specified
// inbuilt class method.
var_dump($method);
?>


Output:

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

Reference: https://www.php.net/manual/en/reflectionclass.getmethod.php

RELATED ARTICLES

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6781 POSTS0 COMMENTS