Originally published on zero2php.dev — part of the Zero to PHP course. View this lesson on the original site.
What constants are
Constants are immutable values. Common styles:
<?php
declare(strict_types=1);
const APP_NAME = 'Demo';
define('LEGACY_MAX', 100);
const vs define
const is compile-time friendly for simple scalars; define() can be used dynamically (rare for beginners).
Naming
Name constants clearly—often UPPER_SNAKE_CASE.
Exercise
Declare a const named STEP with value 11, then echo STEP so the output is 11.
From Zero to PHP — PHP foundations: environment, syntax, and values