Lesson content
Read, practise, then check your understanding
Constants name values that should not be reassigned. Prefer const declarations; define supports runtime names. Class constants group facts with a type, while magic constants depend on source context.
Practical example
<?php
const APP_NAME = 'Learning Portal';
final class Limits { public const MAX_UPLOAD_BYTES = 5_000_000; }
$root = __DIR__;
$className = Limits::class;
Use enums for closed domain sets and deployment configuration for environment-dependent values. Never commit secrets as constants. Magic constants such as __FILE__, __DIR__, and __METHOD__ are useful for diagnostics and relative paths.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.