Thursday, September 4, 2025
HomeLanguagesPHP | get_class_methods() Function

PHP | get_class_methods() Function

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:




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


Output:

Geeks
neveropen

Program 2:




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


Output:

Geeks
neveropen
G4G

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

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS