constant()¶
The constant() function is a PHP native function, which provide the value of a declared global constant, a class constant or an enumeration case.
For class constant and enumeration cases, it may be replaced with the dynamic class constant syntax, introduced in PHP 8.3.
<?php
const A = 1;
echo constant('A');
enum E: string {
case B = 'abc';
const C = 'def';
}
echo constant('E::B')->value; // abc
echo constant('E::C'); // def
?>
Related : Dynamic Class Constant, Class Constant Syntax, Dynamic Constant