PHP | ReflectionClass hasConstant() Function
Last Updated :
04 Dec, 2019
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.
Return Value: This function returns TRUE if the constant is define, FALSE otherwise.
Below programs illustrate the ReflectionClass::hasConstant() function in PHP:
Program 1:
<?php
class Company {
const c1 = 'GeeksforGeeks' ;
}
$constant = new ReflectionClass( "Company" );
$const = $constant ->hasConstant( "c1" );
var_dump( $const );
?>
|
Program 2:
<?php
class Company {
}
$constant = new ReflectionClass( "Company" );
var_dump( $constant ->hasConstant( "c1" ));
?>
|
Reference: https://secure.php.net/manual/en/reflectionclass.hasconstant.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...