Home >Backend Development >PHP Tutorial >How does a PHP function return a class method name?
The get_class_methods() function in PHP can return an array of method names of the class. The parameter is an object, and the return value is a string array containing the class method name. It returns the public method name, including the method name of the parent class. If the argument is not an object, an empty array is returned.
The get_class_methods()
function in PHP can return an array of method names of a class.
get_class_methods(object $object): array
$object
: The object to get the method name. A string array containing the name of the class method.
Consider the following class:
class User { public function getName() { // ... } public function getEmail() { // ... } }
To get the method name of the User
class, you can use get_class_methods()
Function:
$user = new User(); $methods = get_class_methods($user); print_r($methods);
Output:
Array ( [0] => getName [1] => getEmail )
The function returns the public method name.
The above is the detailed content of How does a PHP function return a class method name?. For more information, please follow other related articles on the PHP Chinese website!