Get User Defined Constants in PHP

PHP function - get_defined_constants()  gives all the constants defined in current scope.  It can be CORE Constants, extensions defined constants and user defined constants. As a developer you may be interested in all defined constants or user defined constants at a time. As the total number of constants printed on screen can be very high, you may like to print the concerned constants at a time.

For user defined constants:

$const = get_defined_constants(true);

For Core Constant, user 'Core' as keyword -

For checking all values in the function, just print it as see what is stored within it.

The categorize parameter to get_defined_constants() was added in PHP 5.

  • # 1 - by check website

    Do you know some of the reasons why you would need to have all of the constants ?

  • # 2 - by Satya Prakash

    Do not know. But you may need to know all user defined constants.
    Possibly among all kind of constants you can looks at extension constants
    coming into the scope!

  • # 3 - by ideapad

    Your blog is very interesting!
    May I exchange links with you?
    I will come to visit your blog usually!

    • # 4 - by Satya Prakash

      Currently I am very tired with my blog change. Something wrong has happened with my original theme.

Comments are open for an year period. Please, write here on Facebook page.