How to use get_class_methods() function to get the class methods names in PHP

2 Answers

0 votes
class Test 
{
    public $pr = "Property from class Test";
      
    public function Test()
    {
        echo 'Constructor activated from class Test <br />';
    }
        
    public function __destruct()
    {
        echo '<br /> Destructor activated from class Test <br />';
    }
      
    public function setProperty($val)
    {
        $this->pr = $val;
    }
      
    public function getProperty()
    {
        return $this->pr;
    }
     
    public function f1() 
    {
        echo '<br /> f1() <br />';
    }    
     
    public function f2() 
    {
        echo '<br /> f2() <br />';
    }
}
    
$class_methods = get_class_methods('Test');
foreach ($class_methods as $method_name) 
      echo "Method: $method_name <br />";
 
 
/*
run:
 
Method: Test
Method: __destruct
Method: setProperty
Method: getProperty
Method: f1
Method: f2  
    
*/

 



answered Mar 14, 2016 by avibootz
edited Mar 14, 2016 by avibootz
0 votes
class Test 
{
    public $pr = "Property from class Test";
     
    public function Test()
    {
        echo 'Constructor activated from class Test <br />';
    }
       
    public function __destruct()
    {
        echo 'Destructor activated from class Test <br />';
    }
     
    public function setProperty($val)
    {
        $this->pr = $val;
    }
     
    public function getProperty()
    {
        return $this->pr;
    }
    
    public function f1() 
    {
        echo '<br /> f1() <br />';
    }    
    
    public function f2() 
    {
        echo '<br /> f2() <br />';
    }
}
$class_methods = get_class_methods(new Test());  
foreach ($class_methods as $method_name) 
      echo "Method: $method_name <br />";


/*
run:

Constructor activated from class Test
Destructor activated from class Test
Method: Test
Method: __destruct
Method: setProperty
Method: getProperty
Method: f1
Method: f2  
   
*/

 



answered Mar 14, 2016 by avibootz

Related questions

2 answers 232 views
232 views asked Oct 4, 2017 by avibootz
2 answers 278 views
2 answers 318 views
318 views asked Nov 4, 2015 by avibootz
1 answer 199 views
199 views asked Nov 4, 2015 by avibootz
3 answers 345 views
345 views asked Nov 3, 2015 by avibootz
1 answer 342 views
...