Open In App

PHP | ReflectionClass getMethods() Function

Last Updated : 06 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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



Similar Reads

PHP | ReflectionClass getDefaultProperties() Function
The ReflectionClass::getDefaultProperties() function is an inbuilt function in PHP which is used to return the default properties including inherited properties from a specified class. Syntax: ReflectionClass::getDefaultProperties(void) : array Parameters: This function does not accept any parameter. Return Value: This function returns an array of
2 min read
PHP | ReflectionClass getReflectionConstants() Function
The ReflectionClass::getReflectionConstants() function is an inbuilt function in PHP which is used to return an array of ReflectionClassConstant objects. Syntax: array ReflectionClass::getReflectionConstants( void ) Parameters: This function does not accept any parameters. Return Value: This function returns an array of ReflectionClassConstant obje
2 min read
PHP | ReflectionClass getInterfaceNames() Function
The ReflectionClass::getInterfaceNames() function is an inbuilt function in PHP which is used to return an array of interface names as values. Syntax: array ReflectionClass::getInterfaceNames( void ) Parameters: This function does not accept any parameters. Return Value: This function returns an array of interface names as values. Below programs il
1 min read
PHP | ReflectionClass getConstant() Function
The ReflectionClass::getConstant() function is an inbuilt function in PHP which is used to return the value of the defined constant. Syntax: mixed ReflectionClass::getConstant( string $name ) Parameters: This function accepts a parameter Name which is the name of the defined constant. Return Value: This function returns the value of the defined con
1 min read
PHP | ReflectionClass getExtensionName() Function
The ReflectionClass::getExtensionName() function is an inbuilt function in PHP which is used to return the name of the extension which define the class or false for user-defined classes.Syntax: string ReflectionClass::getExtensionName( void ) Parameters: This function does not accept any parameters.Return Value: This function returns the name of th
1 min read
PHP | ReflectionClass getExtension() Function
The ReflectionClass::getExtension() function is an inbuilt function in PHP which is used to return the ReflectionExtension object which represents the extension for the defined class, or NULL for the user-defined classes. Syntax: ReflectionExtension ReflectionClass::getExtension( void ) Parameters: This function does not accept any parameters. Retu
1 min read
PHP | ReflectionClass getStartLine() Function
The ReflectionClass::getStartLine() function is an inbuilt function in PHP which is used to return the line number from where the user defined class get started. Syntax: int ReflectionClass::getStartLine( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the line number from where the user defined
1 min read
PHP | ReflectionClass getEndLine() Function
The ReflectionClass::getEndLine() function is an inbuilt function in PHP which is used to return the line number where the user defined class get ends. Syntax: int ReflectionClass::getEndLine( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the line number where the user defined class get ends. B
1 min read
PHP | ReflectionClass getDocComment() Function
The ReflectionClass::getDocComment() function is an inbuilt function in PHP which is used to return the specified doc comments if it exists, otherwise returns false. Syntax: string ReflectionClass::getDocComment( void ) Parameters: This function does not accept any parameters.Return Value: This function returns the specified doc comments if it exis
1 min read
PHP | ReflectionClass getStaticPropertyValue() Function
The ReflectionClass::getStaticPropertyValue() function is an inbuilt function in PHP which is used to return the value of the static property. Syntax: mixed ReflectionClass::getStaticPropertyValue( string $name, mixed &$def_value ) Parameters: This function accepts a single parameter name which is the name of the specified static property. Return V
1 min read