I don’t think it’s possible, at least as far as I read from the documentation:
However doing some tests I realized that it is possible to force/trick the syntax, as the @Wallace did in his reply, however the idea here is to create a variable that is an anonymous function, so you will not need the apostrophes, an example:
<?php
define('FOO', 'bar');
$constant = function ($nome) {
return $nome;
};
echo "FOO = {$constant(FOO)}";
Another example taking "native constants":
<?php
$constant = function ($nome) {
return $nome;
};
echo "PHP_VERSION = {$constant(PHP_VERSION)}";
Example in the ideone: https://ideone.com/vSJ05m
If it doesn’t exist as define()
will display exactly what was written:
<?php
$constant = function ($nome) {
return $nome;
};
echo "BAZ = {$constant(BAZ)}"; //Exibe "BAZ = BAZ"
Inelegant is using constants to display information.. makes no sense at all.
– Natanael Lopes
Maybe it’s just your opinion. What about the magic constants? We have to use them (whether we want to or not) to display a line in a file, for example. In this sense the question becomes useful. Example with the @rray response.
printf('A linha do arquivo é %s e o arquivo é o %s', __LINE__, __FILE__);
– Wallace Maxters
I wouldn’t do that by concatenating!
– Wallace Maxters