Home > Article > Backend Development > How to query the methods in a class in php
In PHP, you can use the get_class_methods() function to query what methods are in a class. This function can get all the methods of the class and return an array composed of the method names of the class. The syntax is "get_class_methods(class name) ')".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use the get_class_methods() function To query what methods are in the class.
The get_class_methods() function can get all the methods of the class and return an array composed of the method names of the class.
Syntax:
get_class_methods($class_name)
$class_name
: Class name or object instance.
Return value: Returns an array consisting of the method names defined in the class specified by $class_name
. If an error occurs, null is returned.
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<br>"; } ?>
Output result:
PHP Video Tutorial"
The above is the detailed content of How to query the methods in a class in php. For more information, please follow other related articles on the PHP Chinese website!