Friday, November 14, 2025
HomeLanguagesPHP | ReflectionClass hasMethod() Function

PHP | ReflectionClass hasMethod() Function

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
 
// Initialising a user-defined Class Departments
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 hasMethod() function
$methods = $class->hasMethod('CSE');
 
// Getting the value true or false
var_dump($methods);
?>


Output: 

bool(true)

 

Program 2: 
 

php




<?php
  
// Initialising a user-defined Class Company
class Company {
    public function neveropen() { }
    static function gfg() { }
}
  
// Using ReflectionClass() over the
// user-defined class Company
$class = new ReflectionClass('Company');
  
// Calling the hasMethod() function
$methods = $class->hasMethod('TCS');
  
// Getting the value true or false
var_dump($methods);
?>


Output: 

bool(false)

 

Reference: https://php.net/manual/en/reflectionclass.hasmethod.php
 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7142 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS