Home > Article > Backend Development > How to get all methods of a class in php
php method to obtain all methods of a class: You can use the get_class_methods() function to obtain it. The get_class_methods() function returns an array consisting of the method names of the class, or NULL if it fails.
get_class_methods() function returns an array consisting of the method names of the class.
(Recommended tutorial: php graphic tutorial)
Syntax:
array get_class_methods ( mixed $class_name )
Returns the method name defined in the class specified by class_name Array composed of. If an error occurs, NULL is returned.
Note: Starting with PHP 4.0.6, you can specify the object itself instead of class_name.
(Video tutorial recommendation: php video tutorial)
For example:
<?php $class_methods = get_class_methods($my_object); // see below the full example ?>
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 Result:
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!