PHP | ReflectionClass getConstructor() Function
Last Updated :
30 Nov, 2019
The ReflectionClass::getConstructor() function is an inbuilt function in PHP which is used to return the constructor of the specified class or NULL if the class is not having any constructor.
Syntax:
ReflectionMethod ReflectionClass::getConstructor( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns the constructor of the specified class or NULL if the class is not having any constructor.
Below programs illustrate the ReflectionClass::getConstructor() function in PHP:
Program 1:
<?php
$Class = new ReflectionClass( 'ReflectionClass' );
$constructor = $Class ->getConstructor();
var_dump( $constructor );
?>
|
Output:
object(ReflectionMethod)#2 (2) {
["name"]=>
string(11) "__construct"
["class"]=>
string(15) "ReflectionClass"
}
Program 2:
class Company {
public function GeeksforGeeks() { }
static function gfg() { }
}
$A = new ReflectionClass( "Company" );
$B = $A ->getConstructor();
var_dump( $B );
?>
|
Reference: https://www.php.net/manual/en/reflectionclass.getconstructor.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...