320 of 410 menu

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

get_class_methods(object|string $class);

Example

Get methods of the built-in class stdClass:

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

Code execution result:

[]

Example

Create a class with several methods and get their list:

<?php class MyClass { public function method1() {} public function method2() {} private function method3() {} } $res = get_class_methods('MyClass'); print_r($res); ?>

Code execution result:

['method1', 'method2']

Example

Get class methods through an object:

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

Code execution result:

['method1', 'method2']

See Also

byenru