Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Const

const is a PHP keyword, that creates constant definitions.

const is allowed inside classes, interfaces, enumerations and traits, to create static constants. const is also allowed in the global scope, to create global constants.

const is only allowed in the body of a classes, interfaces, enumerations and traits, and the first level of a main file. It is not possible to create conditioned constants with a if-then structure and const: this requires an include.

<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>

Documentation

See Also