PHP | ReflectionClass getConstants() Function Last Updated : 30 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The ReflectionClass::getConstants() function is an inbuilt function in PHP which is used to return an array of the specified constant names. Syntax: array ReflectionClass::getConstants( void ) Parameters: This function does not accept any parameter. Return Value: This function returns an array of the specified constant names. Below programs illustrate the ReflectionClass::getConstants() function in PHP: Program 1: php <?php // Declaring a class named as Company class Company { // Defining some constants const First = "GeeksforGeeks"; const Second = "GFG"; } // Using the ReflectionClass() function // over the Company class $A = new ReflectionClass('Company'); // Calling the getConstants() function $a = $A->getConstants(); // Getting an array of the constants print_r($a); ?> Output: Array ( [First] => GeeksforGeeks [Second] => GFG ) Program 2: php <?php // Declaring a class named as Departments class Departments { // Defining some constants const First = "CSE"; const Second = "ECE"; const Third = "EE"; const Fourth = "Mechanical"; } // Using the ReflectionClass() function // over the Departments class $A = new ReflectionClass('Departments'); // Calling the getConstants() function $a = $A->getConstants(); // Getting an array of the constants print_r($a); ?> Output: Array ( [First] => CSE [Second] => ECE [Third] => EE [Fourth] => Mechanical ) Reference: https://www.php.net/manual/en/reflectionclass.getconstants.php Comment More infoAdvertise with us Next Article PHP | ReflectionClass getConstants() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-function PHP- ReflectionClass PHP- Reflection +1 More Similar Reads PHP | ReflectionClass getConstant() Function The ReflectionClass::getConstant() function is an inbuilt function in PHP which is used to return the value of the defined constant. Syntax: mixed ReflectionClass::getConstant( string $name ) Parameters: This function accepts a parameter Name which is the name of the defined constant. Return Value: 1 min read PHP | ReflectionClass hasConstant() Function The ReflectionClass::hasConstant() function is an inbuilt function in PHP which is used to check the specified constant is present or not. Syntax: bool ReflectionClass::hasConstant( string $name ) Parameters: This function accepts a single parameter $name which holds the name of the defined constant 1 min read PHP | ReflectionClass getConstructor() Function 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 a 1 min read PHP | ReflectionClass getReflectionConstants() Function The ReflectionClass::getReflectionConstants() function is an inbuilt function in PHP which is used to return an array of ReflectionClassConstant objects. Syntax: array ReflectionClass::getReflectionConstants( void ) Parameters: This function does not accept any parameters. Return Value: This functio 2 min read PHP | ReflectionClass getReflectionConstant() Function The ReflectionClass::getReflectionConstant() function is an inbuilt function in PHP which is used to return the ReflectionClassConstant of the specified class's property. Syntax: ReflectionClassConstant ReflectionClass::getReflectionConstant( string $name ) Parameters: This function accepts a single 2 min read Like