Home > Article > Backend Development > How to get all methods of a class in php
php can use the get_class_methods() function to obtain all methods of a class. This function can return an array consisting of the method names of the class, or NULL if an error occurs. Function syntax: [get_class_methods($class_name)].
php provides us with a function get_class_methods, which can return an array composed of class method names, and returns NULL if an error occurs.
(Recommended video tutorial: php video tutorial)
Grammar:
array get_class_methods ( mixed $class_name )
(Related recommendation: php training)
Code example:
<?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"; }
Output:
myclass myfunc1 myfunc2
The above is the detailed content of How to get all methods of a class in php. For more information, please follow other related articles on the PHP Chinese website!