PHP | ReflectionClass getMethods() Function Improve Article Save Article Like Article
Improve Article Save Article The ReflectionClass::getMethods() function is an inbuilt function in PHP which is used to return an array of specified methods. array ReflectionClass::getMethods( int $filter ) Parameters: This function accepts a single parameter filter which is used to remove some of the methods. php
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>0
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>2 <?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>3 function <?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>5
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>7 <?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>8 function array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }0
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>8 function array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }4
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>7 function array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }8 array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }9
Output <?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?> Program 2: php
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>0
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>2 <?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>3 function <?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>5
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>7 <?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>8 function array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }0
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>8 function array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }4
<?php // Initialising a user-defined Class class Departments { public function CSE() { } final protected function ECE() { } private static function EE() { } static function IT() { } private function Mechanical() { } } // Using ReflectionClass() over the // user-defined class Departments $class = new ReflectionClass('Departments'); // Calling the getMethods() function $methods = $class->getMethods(); // Getting an array of specified methods var_dump($methods); ?>7 function array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }8 array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }9
Output: array(2) { [0]=> object(ReflectionMethod)#2 (2) { ["name"]=> string(2) "EE" ["class"]=> string(11) "Departments" } [1]=> object(ReflectionMethod)#3 (2) { ["name"]=> string(2) "IT" ["class"]=> string(11) "Departments" } }
Reference: https://www.php.net/manual/en/reflectionclass.getmethods.php My Personal Notes arrow_drop_up Save Please Login to comment... |