Related Articles

Related Articles

PHP | get_class_methods() Function
  • Last Updated : 16 Apr, 2020

The get_class_methods() function is an inbuilt function in PHP which is used to get the class method names.

Syntax:

array get_class_methods( mixed $class_name )

Parameters: This function accepts a single parameter $class_name which holds the class name or an object instance.

Return Value: This function returns an array of method names defined for the class on success and returns NULL in case of error.

Below programs illustrate the get_class_methods() function in PHP:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a class
class GFG {
  
    public function Geeks() {
        var_dump(get_called_class());
    }
      
    public function GeeksforGeeks() {
        var_dump(get_called_class());
    }
}
  
$getClassMethod = get_class_methods('GFG');
  
foreach ($getClassMethod as $method) {
    echo "$method\n";
}
  
?>

chevron_right


Output:

Geeks
GeeksforGeeks

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a class
class GFG {
  
    public function Geeks() {
        var_dump(get_called_class());
    }
      
    public function GeeksforGeeks() {
        var_dump(get_called_class());
    }
      
    public function G4G() {
        // Empty method
    }
}
  
class_alias('GFG', 'GeeksforGeeks');
  
$getClassMethod = get_class_methods('GeeksforGeeks');
  
foreach ($getClassMethod as $method) {
    echo "$method\n";
}
  
?>

chevron_right


Output:

Geeks
GeeksforGeeks
G4G

Reference: https://www.php.net/manual/en/function.get-class-methods.php




My Personal Notes arrow_drop_up
Recommended Articles
Page :