'Does PHP have syntax sugar for `defined('X') && X`?

I often have to check the value of a constant, but it's not guaranteed that to exist. The typical way is if ( defined( 'X' ) && X ), but that gets annoying to type when a constant has a good, descriptive name.

It feels like there should be a shortcut, something like constant( 'X', $default_value ) or if ( X ?? false ), but haven't found anything that works. Everything throws an E_WARNING, returns an unexpected value, or both.

I could write my own constant_value( $name, $default ) function, but that would have to be added to every project I work on, and would be a non-standard thing for other devs to have to learn.

I don't see any RFC's that seem relevant.

I'm guessing the answer is "no", but wanted to make sure I haven't missed something.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source