Home >Backend Development >PHP Tutorial >PHP get_class_methods function usage_PHP tutorial
The function of get_class_methods function is to return an array composed of the method names of the class. This article will briefly share the related usage of this function.
Function prototype array get_class_methods (mixed $class_name)
Returns an array consisting of method names defined in the class specified by class_name. If an error occurs, NULL is returned.
Note: Starting with PHP 4.0.6, it is possible to specify the object itself instead of class_name. Specific examples of use of get_class_methods() are as follows:
<?php class myclass { // constructor function myclass() { return(true); } // method 1 function myfunc1() { return(true); } // method 2 function myfunc2() { return(true); } } $class_methods = get_class_methods('myclass'); // or $class_methods = get_class_methods(new myclass()); foreach ($class_methods as $method_name) { echo $method_name,'<br />'; }
The above example will output:
myclass
myfunc1
myfunc2
Note:
Since PHP 5, this function returns the method's defined name (case-sensitive). In PHP 4 always returns lowercase.