Class and Object Function in PHP

Introduction
 
In this article I will discuss the "get_declare_classes()" and "get_class_method()" functions in PHP. These functions are for classes and objects in PHP.
 
First of all I am using the get_declare_classes() function. This function returns an array of class names of classes defined in the current program.
 
Syntax
 
get_declare_classes(void);
 
Parameter
void void means no parameter required
 
Example
  1. <?php  
  2. echo "<pre>";  
  3. print_r(get_declared_classes());  
  4. ?>  
Returns an array of the class names of the defined classes in this code.
 
Output
 
get declare classes function in php.jpg
 
This function either returns an array of the method names of the specified class names or returns the errors. 
 
Syntax
 
get_class_method($class_name);
 
Parameter
class name Required the class name
 
Example
  1. <?php  
  2. class vinod  
  3. {  
  4.         function vinod()  
  5.     {  
  6.         return(true);  
  7.     }  
  8.     function myfuncA()  
  9.     {  
  10.         return(true);  
  11.     }  
  12.     function myfuncB()  
  13.     {  
  14.         return(true);  
  15.     }  
  16. }  
  17. $class_methods = get_class_methods('vinod');  
  18. $class_methods = get_class_methods(new vinod());  
  19.    
  20. foreach ($class_methods as $method_name)  
  21. {  
  22.     echo "$method_name<br>";  
  23. }  
  24.    
  25. ?>  
Returns an array of the method names specified by the class.
 
get class method function in php.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all