To view the methods of classes in php, we can use the get_class_methods() method. This function can return an array consisting of class method names, for example: [get_class_methods($my_object)].
get_class_methods — Returns an array consisting of class method names.
(Recommended tutorial: php graphic tutorial)
Description
array get_class_methods ( mixed $class_name )
Returns an array consisting of the method names defined in the class specified by class_name. If an error occurs, NULL is returned.
Note: Starting from PHP 4.0.6, you can specify the object itself instead of class_name, such as
<?php $class_methods = get_class_methods($my_object); // see below the full example ?>
(Learning video recommendation: php video tutorial)
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 view class methods in php. For more information, please follow other related articles on the PHP Chinese website!