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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
30 Nov, 2019
Like Article
Save Article