get_class_methods()
get_class_methods() — Gets the class methods' names.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
get_class_methods(object|string $object_or_class): array
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $object_or_class | object|string | The class name or an object instance |
Return value
Returns an array of method names defined for the class specified by object_or_class.
Example
A runnable snippet:
class myclass { // constructor function __construct() { 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\n"; }
Output:
__construct myfunc1 myfunc2
Changelog
| Version | Change |
|---|---|
| 8.0.0 | The object_or_class parameter now only accepts objects or valid class names. |
See also
get_class(), get_class_vars(), get_object_vars()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page get_class_methods() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.