Skip to content
Related Articles

Related Articles

PHP constant() Function
  • Last Updated : 31 Dec, 2020

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 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

PHP




<?php
  
// Define a constant
define("Home","Welcome to GeeksforGeeks");
  
echo constant("Home");
?>

Output:

Welcome to GeeksforGeeks

Example 2:  Case insensitive

PHP




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

Output: 

True denotes case-insensitive

Reference: https://www.php.net/manual/en/function.constant.php

My Personal Notes arrow_drop_up
Recommended Articles
Page :