Syntax:ReflectionClass ReflectionMethod::getDeclaringClass (void)
Parameters:This function takes no parameters.
Return value:This function returns the declared class name for the reflected method.Below the program illustrate the function
ReflectionMethod::getDeclaringClass() :
Program 1:
// Class declaration
class
GeeksforGeeks {
// Declare a protected function
protected
function
CSportal (
$name
) {
// Displays the output
return
’Geeks’
.
$name
;
}
}
// Create ReflectionMethod object
$reflectionMethod
=
new
ReflectionMethod (
new
GeeksforGeeks() ,
’CSportal’
);
// Call the getDeclaringClass function
var_dump (
$reflectionMethod
-> getDeclaringClass());
?>
Output:object (ReflectionClass) # 2 (1) {["name"] = > string (13) "GeeksforGeeks"}
Program 2:
// Class declaration
class
NidhiSingh {
// Protected function declaration
protected
function
Author (
$name
) {
// Displays output
return
’Nidhi’
.
$name
;
}
}
// Create ReflectionMethod object
$reflectionMethod
=
new
ReflectionMethod (
new
NidhiSingh() ,
’Author’
);
// Call the getDeclaringClass function
var_dump (
$reflectionMethod
-> getDeclaringClass());
?>
Output:object (ReflectionClass) # 2 (1) {["name"] = > string (10) "NidhiSingh"}
Link: https://www.php.net/manual/en/reflectionmethod.getdeclaringclass.php .