Thursday, October 23, 2025
HomeLanguagesPHP | ReflectionClass getReflectionConstants() Function

PHP | ReflectionClass getReflectionConstants() Function

The ReflectionClass::getReflectionConstants() function is an inbuilt function in PHP which is used to return an array of ReflectionClassConstant objects.

Syntax:

array ReflectionClass::getReflectionConstants( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns an array of ReflectionClassConstant objects.

Below programs illustrate the ReflectionClass::getReflectionConstants() function in PHP:
Program 1:




<?php
  
// Declaring a class named as Company
class Company {
      
    // Defining some constants
    const First = "neveropen";
    const Second = "GFG";
}
  
// Using the ReflectionClass() function 
// over the Company class
$A = new ReflectionClass('Company');
  
// Calling the getReflectionConstants() function
$a = $A->getReflectionConstants();
  
// Getting an array of ReflectionClassConstant objects.
print_r($a);
?>


Output:

Array
(
    [0] => ReflectionClassConstant Object
        (
            [name] => First
            [class] => Company
        )

    [1] => ReflectionClassConstant Object
        (
            [name] => Second
            [class] => Company
        )

)

Program 2:




<?php
  
// Using the ReflectionClass() function 
$A = new ReflectionClass('ReflectionClass');
  
// Calling the getReflectionConstants() function
$a = $A->getReflectionConstants();
  
// Getting an array of ReflectionClassConstant objects.
print_r($a);
?>


Output:

Array
(
    [0] => ReflectionClassConstant Object
        (
            [name] => IS_IMPLICIT_ABSTRACT
            [class] => ReflectionClass
        )

    [1] => ReflectionClassConstant Object
        (
            [name] => IS_EXPLICIT_ABSTRACT
            [class] => ReflectionClass
        )

    [2] => ReflectionClassConstant Object
        (
            [name] => IS_FINAL
            [class] => ReflectionClass
        )

)

Reference: https://secure.php.net/manual/en/reflectionclass.getreflectionconstants.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS