get_class_methods
Returns the names of a class's methods.
Syntax
get_class_methods(object|string $object_or_class): arrayParameters
| Parameter | Type | Description |
|---|---|---|
| $object_or_class | object|string | An object or a class name. |
Return value
arrayAn array of the method names accessible from the calling scope.
Examples
The methods of a class:
<?php
class Cart
{
public function add(): void {}
public function total(): int { return 0; }
private function recalculate(): void {}
}
echo implode(', ', get_class_methods(Cart::class));Output:
add, totalNotes
Private methods are not visible from outside. To check for a single method use method_exists().
See also
- method_exists — Checks whether a class or an object has a method.
- get_object_vars — Returns the accessible properties of an object as an array.
- ReflectionClass — Information about a class: its methods, properties and attributes.
In the tutorial
- Classes and objects — What classes and objects are in PHP, how to describe properties and methods and create objects.