The get_class_methods
method can be used to get the name of the list of methods available in the class.
get_class_methods(object|string $object_or_classname): array
We can pass the class name or object instance as an argument.
This method will return an array.
<?phpclass MyClass {public $name;// constructorfunction __construct($name) {$this->name = $name;}//static functionpublic static function staticFn() {echo "Static Function!";}// normal functionfunction set($n) {$this->name = $n;}function get(){return $this->name;}}echo "Getting class method using class name\n";print_r(get_class_methods('MyClass'));echo "\nGetting class method using object\n";print_r(get_class_methods(new MyClass("PHP")));?>
In the code above:
We created a MyClass
class with a constructor, methods, and static method.
We first called the get_class_methods
function with the class name as an argument, then used the MyClass
object as an argument. Both the function calls will return an array with the name of the available methods in the MyClass
class.