Home > Article > Backend Development > How to get all method names in a class in php
php method to get all the method names in the class: You can use the [get_class_methods()] function to get it. The [get_class_methods()] function can return all the method names in the specified class and save the method names. into the array.
[Related learning recommendations: php programming (video)]
php method to get all method names of a class:
1. Get the line number, file path file name, class name, Constants for method names
__LINE__
: The current line number in the file.
__FILE__
: The full path and file name of the file.
If used in an include file, returns the include file name. As of PHP 4.0.2, __FILE__ always contains an absolute path, while versions before that sometimes contained a relative path.
__FUNCTION__
: Function name (newly added in PHP 4.3.0).
Since PHP 5, this constant returns the name of the function when it was defined (case-sensitive). In PHP 4 this value is always lowercase.
__CLASS__
: The name of the class (newly added in PHP 4.3.0).
Since PHP 5, this constant returns the name of the class when it was defined (case-sensitive). In PHP 4 this value is always lowercase.
__METHOD__
: The method name of the class (newly added in PHP 5.0.0). Returns the name of the method as it was defined (case-sensitive).
Note: These constants are preceded and followed by two underscores.
2. Methods to obtain class names, method names, and variable names
I found that one of the powerful features of PHP is that there are often unexpected functions or these Constants help you complete certain functions conveniently. I understand more and more why there are so many questions testing specific PHP functions in the PHP competition questions.
Find some other constants or functions in one breath and continued to add them.
get_class(class name); //取得当前语句所在类的类名
get_class_methods(class name); //取得class name 类的所有的方法名,并且组成一个数组
get_class_vars(class name); //取得class name 类的所有的变亮名,并组成一个数组
If you want to know more about programming learning, please pay attention to the php training column!
The above is the detailed content of How to get all method names in a class in php. For more information, please follow other related articles on the PHP Chinese website!