PHP | ReflectionClass getReflectionConstant() Function
Last Updated :
30 Nov, 2019
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 parameter name which is the name of the class constant.
Return Value: This function returns the ReflectionClassConstant of the specified class’s property.
Below programs illustrate the ReflectionClass::getReflectionConstant() function in PHP:
Program 1:
<?php
class Company {
const First = "GeeksforGeeks" ;
const Second = "GFG" ;
}
$A = new ReflectionClass( 'Company' );
$a = $A ->getReflectionConstant( 'First' );
print_r( $a );
?>
|
Output:
ReflectionClassConstant Object
(
[name] => First
[class] => Company
)
Program 2:
<?php
class Departments {
const D1 = "EE" ;
const D2 = "Civil" ;
const D3 = "CSE" ;
const D4 = "IT" ;
}
$A = new ReflectionClass( 'Departments' );
$a1 = $A ->getReflectionConstant( 'D1' );
$a2 = $A ->getReflectionConstant( 'D2' );
$a3 = $A ->getReflectionConstant( 'D3' );
$a4 = $A ->getReflectionConstant( 'D4' );
print_r( $a1 );
print_r( $a2 );
print_r( $a3 );
print_r( $a4 );
?>
|
Output:
ReflectionClassConstant Object
(
[name] => D1
[class] => Departments
)
ReflectionClassConstant Object
(
[name] => D2
[class] => Departments
)
ReflectionClassConstant Object
(
[name] => D3
[class] => Departments
)
ReflectionClassConstant Object
(
[name] => D4
[class] => Departments
)
Reference: https://www.php.net/manual/en/reflectionclass.getreflectionconstant.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...