Friday, October 10, 2025
HomeLanguagesPHP | ReflectionClass getMethods() Function

PHP | ReflectionClass getMethods() Function

The ReflectionClass::getMethods() function is an inbuilt function in PHP which is used to return an array of specified methods.
Syntax: 

array ReflectionClass::getMethods( int $filter )

Parameters: This function accepts a single parameter filter which is used to remove some of the methods.
Return Value: This function returns an array of specified methods.
Below programs illustrate the ReflectionClass::getMethods() function in PHP:
Program 1:  

php




<?php
 
// Initialising a user-defined Class
class Departments {
    public function CSE() { }
    final protected function ECE() { }
    private static function EE() { }
    static function IT() { }
    private function Mechanical() { }
}
 
// Using ReflectionClass() over the
// user-defined class Departments
$class = new ReflectionClass('Departments');
 
// Calling the getMethods() function
$methods = $class->getMethods();
 
// Getting an array of specified methods
var_dump($methods);
?>


Output

&lt;?php

// Initialising a user-defined Class
class Departments {
    public function CSE() { }
    final protected function ECE() { }
    private static function EE() { }
    static function IT() { }
    private function Mechanical() { }
}

// Using ReflectionClass() over the
// user-defined class Departments
$class = new ReflectionClass('Departments');

// Calling the getMethods() function
$methods = $class-&gt;getMethods();

// Getting an array of specified methods
var_dump($methods);
?&gt;

Program 2: 

php




<?php
 
// Initialising a user-defined Class
class Departments {
    public function CSE() { }
    final protected function ECE() { }
    private static function EE() { }
    static function IT() { }
    private function Mechanical() { }
}
 
// Using ReflectionClass() over the
// user-defined class Departments
$class = new ReflectionClass('Departments');
 
// Calling the getMethods() function
$methods = $class->getMethods(ReflectionMethod::IS_STATIC);
 
// Getting an array of specified methods
var_dump($methods);
?>


Output: 

array(2) {
  [0]=>
  object(ReflectionMethod)#2 (2) {
    ["name"]=>
    string(2) "EE"
    ["class"]=>
    string(11) "Departments"
  }
  [1]=>
  object(ReflectionMethod)#3 (2) {
    ["name"]=>
    string(2) "IT"
    ["class"]=>
    string(11) "Departments"
  }
}

 

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

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7099 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS