Skip to content
Related Articles

Related Articles

PHP constant() Function

Improve Article
Save Article
Like Article
  • Last Updated : 31 Dec, 2020

The constant() function returns the value of a constant. It also works with class constants. 



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 returns NULL.

Note: It works on PHP 4.0 or newer versions.

Exceptions: If the constant is not defined, it throws an E_WARNING error. It gives a run time warning without script termination.

The following are the PHP programs to show the working of the constant() function.

Example 1: Case sensitive


// Define a constant
define("Home","Welcome to GeeksforGeeks");
echo constant("Home");


Welcome to GeeksforGeeks

Example 2:  Case insensitive


// Define a case insensitive constant
define("GFGConstant","True denotes case-insensitive", true);
echo constant("gfgconstant");


True denotes case-insensitive


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!