Class constant in a string in PHP

后端 未结 3 537
醉梦人生
醉梦人生 2021-02-07 02:57

My reading of the manual (the bit just before the section heading \"String access and modification by character\") is that you can do some fancy tricks with class constants and

3条回答
  •  星月不相逢
    2021-02-07 03:41

    Is the right solution here to concatenate?

    Yes. The extended curly syntax doesn't support it.

    Alternatively, you could export the list of constants to an array and use it (or export the constant to a single scalar variable name), but that's not really a good solution IMO.

    Note that constants are available, as you can do this:

    const k = 'foo';
    $foo = 'bar';
    echo "{${c::k}}"
    

    giving you bar, but that's not what you want.

提交回复
热议问题