PHP Constants

PHP constants tutorial explain you What is constants and How it is differnt from variables length in PHP? with simple examples.

PHP constant is a name or an identifier for a simple value. PHP constant value can’t change throughout the execution of the script.

A constant name begins with a letter or underscore, followed by any number of letters, numbers, or underscores.

By default constant is case-sensitive. Constant identifiers are always uppercase.If you have defined a constant, it can never be changed or undefined.

Syntax for constants in PHP

constant: Required. Specifies the name of the constant to check.

Some valid constant names

define(“SOMEVALUE”,     “valid”);
define(“SOMEVALUE2”,    “valid”);
define(“SOMEVALUE_3”, “valid”);

Invalid constant names

define(“2SOMEVALUE”,    “invalid “);
define(“__SOMEVALUE__”, “invalid “);

Example on PHP constants

Output will be:

Previous articlePHP POST Variables
Next articlePHP echo and print Statement
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!