Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

get_class_methods() function in PHP

 How to get the Methods of in a Class


The get_class_methods() function gets the class methods’ names. It returns an array of method names defined for the class specified by name_of_class. In case of an error, it returns NULL.

It gets the class methods names. Returns an array of method names defined for the class specified by class_name. In case of an error, it returns NULL.

Syntax
get_class_methods(class)

Parameters
name_of_class − The class name. Required!

Return

The get_class_methods() function returns an array of method names defined for the class specified by name_of_class. In case of an error, it returns NULL.

Example

<?php
   class A {
      function A() {
         return(true);
      }
      
      function myfunc1() {
         return(true);
      }
      
      function myfunc2() {
         return(true);
      }
   }
	
   // $method = get_method('A');
   // OR
$method = get_method(new A());
   
   foreach ($method as $method_name) {
      echo "$method_name \n";
   }
?>

The above example will output:

A
myfunc1
myfunc2

If you have any query or suggestions, feel free to ask me via the comment section below.


Post a Comment

0 Comments