PHP get_defined_constants() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The get_defined_constants() function is an inbuilt function in PHP that returns the name of all the constants that are currently defined with their values in the form of an associative array. Syntax: get_defined_constants(bool $categorize = false): arrayParameter: This function accepts single parameter that is described below: $categorize: This function returns a multidimensional array that contains categories in the keys for the first dimension & constants with their values will be in the second dimension.Return Value: This function returns an array in the form of keys and values, i.e, key name => value. Example 1: In the below example, we will be called the get_defined_constants() function and print the associative array. Here, the get_defined_constants prints all constant as well as user-defined constants. PHP <?php define("MY_FIRST_CONSTANT",1); print_r(get_defined_constants(true)) ; ?> Output: Array ( [Core] => Array ( [E_ERROR] => 1 [E_RECOVERABLE_ERROR] => 4096 [E_WARNING] => 2 [E_PARSE] => 4 [E_NOTICE] => 8 [E_STRICT] => 2048 [E_DEPRECATED] => 8192 [E_CORE_ERROR] => 16 [E_CORE_WARNING] => 32 [E_COMPILE_ERROR] => 64 [E_COMPILE_WARNING] => 128 [E_USER_ERROR] => 256 [E_USER_WARNING] => 512 [E_USER_NOTICE] => 1024 [E_USER_DEPRECATED] => 16384 [E_ALL] => 32767 [DEBUG_BACKTRACE_PROVIDE_OBJECT] => 1 [DEBUG_BACKTRACE_IGNORE_ARGS] => 2 ) [user] => Array ( [MY_FIRST_CONSTANT] => 1 ) ) Example 2: In the below example, we will print only user define constant user get_defined_constants() function. PHP <?php define("MY_FIRST_CONSTANT",1); print_r(get_defined_constants(true)["user"]) ; ?> Output: Array ( [MY_FIRST_CONSTANT] => 1 )Reference: https://www.php.net/manual/en/function.get-defined-constants.php Comment More infoAdvertise with us Next Article PHP get_defined_constants() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function Similar Reads PHP Defining Constants In a production-level code, it is very important to keep the information as either variables or constants rather than using them explicitly. A PHP constant is nothing but an identifier for a simple value that tends not to change over time(such as the domain name of a website eg. www.geeksforgeeks.or 2 min read PHP constant() Function The constant() function returns the value of a constant. It also works with class constants. Syntax: constant(constant) Parameter Values: constant: It is a required value that specifies the value of the constant. Return Value: It returns the value of a constant if the constant is defined else return 1 min read PHP | get_defined_vars() Function The get_defined_vars() function is an inbuilt function in PHP which is used to returns an array of all defined variables. This function returns a multidimensional array which contains all the list of variables, environment etc. Syntax: array get_defined_vars( void ) Parameters: This function does no 1 min read PHP | defined() function The PHP defined() function is an inbuilt function in PHP which checks whether a constant is exists or not, in other words, defined or not. Syntax: bool defined($constant_name); Parameter: This function accepts a single parameter as mentioned above and described below. $constant_name: This is require 1 min read PHP define() Function The define() function is basically used by programmers to create constant. Constants in PHP are very similar to variables and the only difference between both are the values of constants can not be changed once it is set in a program. define() returns a Boolean value. It will return TRUE on success 2 min read Like