We can define a constant by using the define()- function or by using the const keyword outside a class definition as of PHP 5.3.0. While define() allows a constant to be defined to an arbitrary expression, the const keyword has restrictions as outlined in the below paragraph. Once a constant is defined, it can never be modified or undefined.
As opposed to defined constants using define(), constants defined using the keyword const must be declared at the top level scope because they are defined at compile-time. This means that they cannot be declared inside functions, if statements, loops or try/ catchblocks.
Defining Constants using define() :
<?php define("CONSTANT", "Slightbook."); echo CONSTANT; // outputs "Slightbook." echo Constant; // outputs "Constant" and issues a notice. ?>
Defining Constants using the const keyword:
<?php const CONSTANT = 'Slightbook'; echo CONSTANT; ?>