Is there a way in PHP to include a constant in a string without concatenating?
No.
In Strings, there is no way for PHP to tell apart string data and 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, neither.
Yes it is (in some way ;) ):
define('FOO', 'bar');
$test_string = sprintf('This is a %s test string', FOO);
This is probably not what you were aiming for, but I think, technically this is not concatenation but a substitution and from this assumption, it includes a constant in a string without concatenating.
If you really want to echo constant without concatenation here is solution:
define('MY_CONST', 300);
echo 'here: ', MY_CONST, ' is a number';
note: in this example echo takes a number of parameters (look at the commas), so it isn't real concatenation
Echo behaves as a function, it takes more parameters, it is more efficient than concatenation, because it doesn't have to concatenate and then echo, it just echoes everything without the need of creating new String concatenated object :))
EDIT
Also if you consider concatenating strings, passings strings as parameters or writing whole strings with " , The , (comma version) is always fastest, next goes . (concatenation with ' single quotes) and the slowest string building method is using double quotes ", because expressions written this way have to be evaluated against declared variables and functions..
You could do:
define( 'FOO', 'bar' );
$constants = get_defined_constants();
$constants = $constants[ 'user' ];
echo "Hello, my name is {$constants['FOO']}";
define('FOO', 'bar');
$constants = create_function('$a', 'return $a;');
echo "Hello, my name is {$constants(FOO)}";