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: This function returns the value of the defined constant.
Below programs illustrate the ReflectionClass::getConstant() function in PHP:
Program 1:
<?php
class Department {
const First = "CSE" ;
}
$A = new ReflectionClass( 'Department' );
$a = $A ->getConstant( 'First' );
print_r( $a );
?>
|
Program 2:
<?php
class Company {
const First = "GeeksforGeeks" ;
const Second = "GFG" ;
const Third = "gfg" ;
}
$A = new ReflectionClass( 'Company' );
print_r( $A ->getConstant( 'First' ));
echo ( "\n" );
print_r( $A ->getConstant( 'Second' ));
echo ( "\n" );
print_r( $A ->getConstant( 'Third' ));
?>
|
Output:
GeeksforGeeks
GFG
gfg
Reference: https://www.php.net/manual/en/reflectionclass.getconstant.php
Last Updated :
30 Nov, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...