The get_class_methods Function

The get_class_methods function returns an array of method names of the specified class. The parameter accepts either a class name as a string or an object of that class. The function returns only public methods of the class.

Syntax

phpget_class_methods(object|string $class);

Example

Get methods of the built-in class stdClass:

php<?php
  $methods = get_class_methods('stdClass');
  print_r($methods);
?>

Code execution result:

php[]

Example

Create a class with several methods and get their list:

php<?php
  class MyClass {
    public function method1() {}
    public function method2() {}
    private function method3() {}
  }

  $res = get_class_methods('MyClass');
  print_r($res);
?>

Code execution result:

php['method1', 'method2']

Example

Get class methods through an object:

php<?php
  $obj = new MyClass();
  $res = get_class_methods($obj);
  print_r($res);
?>

Code execution result:

php['method1', 'method2']

See Also