PHP | ReflectionMethod getDeclaringClass() Function
Last Updated :
28 Nov, 2019
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
class GeeksforGeeks {
protected function CSportal( $name ) {
return 'Geeks ' . $name ;
}
}
$reflectionMethod = new ReflectionMethod( new GeeksforGeeks(), 'CSportal' );
var_dump( $reflectionMethod ->getDeclaringClass());
?>
|
Output:
object(ReflectionClass)#2 (1) {
["name"]=>
string(13) "GeeksforGeeks"
}
Program 2:
<?php
class NidhiSingh {
protected function Author( $name ) {
return 'Nidhi ' . $name ;
}
}
$reflectionMethod = new ReflectionMethod( new NidhiSingh(), 'Author' );
var_dump( $reflectionMethod ->getDeclaringClass());
?>
|
Output:
object(ReflectionClass)#2 (1) {
["name"]=>
string(10) "NidhiSingh"
}
Reference: https://www.php.net/manual/en/reflectionmethod.getdeclaringclass.php.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...