PHP get_class_methods() Function
The PHP get_class_methods() function is used to get the class methods names.
Syntax
get_class_methods(object_or_class)
Parameters
object_or_class |
Required. Specify the class name or an object instance. |
Return Value
Returns an array of method names defined for the class specified by object_or_class.
Example: get_class_methods() example
The example below shows the usage of get_class_methods() function.
<?php class myClass { //class constructor function __construct() { //codes } //method 1 function myfunc1() { //codes } //method 2 function myfunc2() { //codes } } //getting the method names print_r(get_class_methods('myclass')); echo "\n"; //another way of getting the method names print_r(get_class_methods(new myclass())); ?>
The output of the above code will be:
Array ( [0] => __construct [1] => myfunc1 [2] => myfunc2 ) Array ( [0] => __construct [1] => myfunc1 [2] => myfunc2 )
Example: using with derived class
Consider one more example where this function is used with a derived class.
<?php class myClass { //class constructor function __construct() { //codes } //method 1 function myfunc1() { //codes } //method 2 function myfunc2() { //codes } } class newClass extends myClass { //codes } //getting the method names of newClass print_r(get_class_methods('newClass')); ?>
The output of the above code will be:
Array ( [0] => __construct [1] => myfunc1 [2] => myfunc2 )
❮ PHP Classes/Objects Reference