PHP | ReflectionClass hasMethod() Function
Last Updated :
12 Dec, 2021
The ReflectionClass::hasMethod() function is an inbuilt function in PHP which is used to check the specified method is present or not.
Syntax:
bool ReflectionClass::hasMethod( string $name )
Parameters: This function accepts a single parameter $name which holds the name of the method which are being checked.
Return Value: This function returns TRUE if the specified method is present, otherwise returns FALSE.
Below programs illustrate the ReflectionClass::hasMethod() function in PHP:
Program 1:
php
<?php
class Departments {
public function CSE() { }
final protected function ECE() { }
private static function EE() { }
static function IT() { }
private function Mechanical() { }
}
$class = new ReflectionClass( 'Departments' );
$methods = $class ->hasMethod( 'CSE' );
var_dump( $methods );
?>
|
Program 2:
php
<?php
class Company {
public function GeeksforGeeks() { }
static function gfg() { }
}
$class = new ReflectionClass( 'Company' );
$methods = $class ->hasMethod( 'TCS' );
var_dump( $methods );
?>
|
Reference: https://php.net/manual/en/reflectionclass.hasmethod.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...