Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

get_class_methods

Returns the names of a class's methods.

Syntax

get_class_methods(object|string $object_or_class): array

Parameters

ParameterTypeDescription
$object_or_classobject|stringAn 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, total

Notes

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.

Thanks for reading!

Donate to the site — we work hard for you.