有没有办法在String中转换常量或定义的名称? [PHP]

I have a function in PHP that I must pass a string parameter into. I have a file with many constant definitions, like:

define('MSG_CATEGORY_THINGS', things);

I would like to transform my constant MSG_CATEGORY_THINGS into a string with value 'MSG_CATEGORY_THINGS' without putting single quotes in the parameter. Is it possible to do that?

You could recieve all your constants by:

$constants = get_defined_constants(true);
$myConstants = $constants["user"];

This will return an associative array, i.e.

['MSG_CATEGORY_THINGS'=>things]

If you want it as strings you could do:

extract($myConstants)

You will now have a variable called $MSG_CATEGORY_THINGS with a value of things :)