Include constant in string without concatenating

Brian picture Brian · Feb 5, 2010 · Viewed 68.9k times · Source

Is there a way in PHP to include a constant in a string without concatenating?

define('MY_CONSTANT', 42);

echo "This is my constant: MY_CONSTANT";

Answer

Pekka picture Pekka · Feb 5, 2010

No.

With Strings, there is no way for PHP to tell string data apart from constant identifiers. This goes for any of the string formats in PHP, including heredoc.

constant() is an alternative way to get hold of a constant, but a function call can't be put into a string without concatenation either.

Manual on constants in PHP