Global variables and Constants in PHP

Global variables and Constants, both are very much used in PHP applications.

We have already gone through the variable scopes in PHP, where we had learnt what a global variable is and how they function.

The basic essence of Constants in PHP is exactly the same to what we know about it in other programming languages.

Constants once defined cannot be changed. However, global variables can be modified several times in a PHP page, such that, any subsequent access to the global variable gets the most recent modified value and not the one it got initialized with. So, the value of a global variable can keep changing as it goes along.


We use Constants in a PHP application as:

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.