Dynamic Class Constant Edge Cases

../_images/dynamic_class_constant_edges.png

PHP 8.3 introduces a new syntax to access dynamically class constants: class::{constant-name}.

Class constants works with the ?? coalesce operator, as long as the class constant itself has the value null. On the other hand, the ?? does not work with the dynamic class constant, and yields a parse error.

The dynamic class constant syntax works with unquoted constant names, but then, it requires the related global constant to be existing, and holding the actual name of the constant.

Finally, the no scream operator @ does not continue execution in case of a non existing class constant: it masks the error message, and dies.

See Also

PHP Features