PHP  Constants

PHP Constants are variables that once they have been defined,they cannot be changed.

PHP Constants

A constant is a name for a certain value.This value will remain unchanged when the script is execute

All constants should either start with a letter or underscore i.e no $ sign is required when declaring a constant.

NB:All constants are global ,i.e can be called inside a function.

See my Previous Lesson:PHP Strings

How  PHP Constants are created

To create a constant, use the define() function.

Constants are created using  function called define().



  • name-this is the name of the constant
  • value-this is the value held by the constant
  • case-insensitive-specfies if the constant is case-insensitive.Default means its case sensitive

Below example creates a constant that is case-sensitive

define("NAME", "My name is a blogger!");
echo NAME;

Below example creates a constant that is case-insensitive

define("NAME", "My name is a blogger!",true);
echo NAME;

PHP Constants are Global

PHP  Constants  are always global once they have been declared and they can be called anywhere on the script

Below example shows a constant used inside a function despite the fact that its defined outside the function

define("NAME", "My Name is blogger!");

function myName () {
echo NAME;

myName();//Output is “My Name is Blogger!”

See my Next Lesson PHP Operators


About the Author: Eric K

Kenyan Developer and Blogger with Interests in Java,Javascript,Node.js, Wordpress, Android, PHP and Making Money Online. Solving world problems through programming is my passion. Hire me: Email :