Dynamic Class Constant¶
To access a constant value with its name in a string, one required the constant() function. constant('\A::'.$constantName)
.
In PHP 8.3, there is a dedicated syntax, to access those constants dynamically.
PHP code¶
<?php
class a {
public const A = 1;
}
$b = 'A';
echo A::{$b};
?>
Before¶
PHP Parse error: syntax error
After¶
1
PHP version change¶
This behavior changed in 8.3