Constants

Download php eBook

Syntax

  • define ( string $name , mixed $value [, bool $case_insensitive = false ] )
  • const CONSTANT_NAME = VALUE;

Remarks

Constants are used to store the values that are not supposed to be changed later. They also are often used to store the configuration parameters especially those which define the environment (dev/production).

Constants have types like variables but not all types can be used to initialize a constant. Objects and resources cannot be used as values for constants at all. Arrays can be used as constants starting from PHP 5.6

Some constant names are reserved by PHP. These include true, false, null as well as many module-specific constants.

Constants are usually named using uppercase letters.

Related Examples

Stats

101 Contributors: 9
Wednesday, January 4, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook