PHP ReflectionClass hasConstant () function

PHP

Syntax:
bool ReflectionClass::hasConstant (string $name)
Parameters:This function takes one parameter $name,which contains the name of a specific constant.Return value:This function returns TRUE if constant is defined, FALSE otherwise.The following programs illustrate the ReflectionClass::hasConstant() function in PHP:Program 1:  
// Define a custom class Company class Company { const c1 = ' GeeksforGeeks' ;
}  
// Using ReflectionClass over
// defined custom Company class $constant = new ReflectionClass ( "Company" );  
// Calling the hasConstant() function $const = $constant -> hasConstant ( " c1 " );  
// Get TRUE or FALSE var_dump ( $const ); ?>
Exit:
bool (true )
Program 2:  
// Define an empty class class Company { }  
// Using ReflectionClass over
// defined custom Company class $constant = new ReflectionClass ( "Company" );  
// Calling the hasConstant() function and
// get TRUE or FALSE var_dump ( $constant -> hasConstant ( "c1" )); ?>
Exit:
bool (false )
Link: https://secure.php.net /manual/en/reflectionclass.hasconstant.php



Get Solution for free from DataCamp guru