Sunday, June 14, 2026
HomeLanguagesPHP | ReflectionMethod getDeclaringClass() Function

PHP | ReflectionMethod getDeclaringClass() Function

The ReflectionMethod::getDeclaringClass() function is an inbuilt function in PHP which is utilized to return the name of the declared class.

Syntax:

 ReflectionClass ReflectionMethod::getDeclaringClass ( void )

Parameters: This function does not accepts any parameter.

Return Value: This function returns the name of the declared class for the reflected method.

Below programs illustrates the ReflectionMethod::getDeclaringClass() function:

Program 1:




<?php
  
// Declaring a class
class neveropen {
      
    // Declaring a protected function
    protected function CSportal($name) {
          
        // Displays output
        return 'Geeks ' . $name;
    }
  
}
  
// Creating an object of ReflectionMethod
$reflectionMethod = new ReflectionMethod(new neveropen(), 'CSportal');
  
// Calling getDeclaringClass function
var_dump($reflectionMethod->getDeclaringClass());
?>


Output:

object(ReflectionClass)#2 (1) {
  ["name"]=>
  string(13) "neveropen"
}

Program 2:




<?php
  
// Declaring a class
class NidhiSingh {
      
    // Declaring a protected function
    protected function Author($name) {
          
        // Displays output
        return 'Nidhi ' . $name;
    }
  
}
  
// Creating an object of ReflectionMethod
$reflectionMethod = new ReflectionMethod(new NidhiSingh(), 'Author');
  
// Calling getDeclaringClass function
var_dump($reflectionMethod->getDeclaringClass());
?>


Output:

object(ReflectionClass)#2 (1) {
  ["name"]=>
  string(10) "NidhiSingh"
}

Reference: https://www.php.net/manual/en/reflectionmethod.getdeclaringclass.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
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS