No Class Constant In String

../_images/no-constant-in-string.png

Interpolation is injecting variable values inside strings. For complex variables, such as objects, it requires the curly braces to work.

Yet, the simple $object::CONSTANT doesn’t compile. But, the error message mentions it could do something with a square bracket, so it is still possible to access the value of strings by using the array notation.

I wish there was a better way to inject that class name in the string, or, any class constant.

Also, note that the reported class name is the definition one, not the name that was used at instantiation.

So many surprises.

See Also

PHP Features