Tsallaka zuwa abun ciki
Justice Tech School

PHP Constants and Magic Constants

define() and const create constants. Magic constants such as __LINE__, __FILE__, __DIR__, __FUNCTION__ and __CLASS__ change with context.

Example
const APP = "JTS";
define("MAX", 100);
echo APP, " ", MAX, "\n";
function who() { return __FUNCTION__; }
echo who(), " ", __LINE__, "\n";

Result

JTS 100
who 6

Exercise

Create a constant.

 MAX = 5;

Quiz Test

Do constants use a $?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.