Constants in PHP:

A constant is an identifier for a simple value they are same as variables. Value of a constant cannot change or undefined during the execution of script. A constant name should start with a letter or underscore sign.

Constants are case sensitive. Constants are like variables but they do not need “$” sign for declaration. Constants are automatically global for the script.

To define or declare a constant you have to use “define ()” function. The define() function takes three parameters:

  • First parameter defines the name
  • Second parameter defines the value
  • Third parameter is optional in it we pass the case sensitivity in it

Naming Convention:

By naming convention the identifier must be in uppercase and the name of constants start with a letter or underscore and followed by any number, letter or underscore. Always be sure when you naming a constant because you can not change it at run time.


This example is without case sensitivity parameter and it will give an error on browser because we didn’t set the case sensitivity


This example is with case sensitivity parameter means it will also give the output of “welcome” because we set the case sensitivity to true.


Leave a Reply

Your email address will not be published. Required fields are marked *