Class constant in a string in PHP

后端 未结 3 532
醉梦人生
醉梦人生 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:49

    The curly syntax only works for 'variable expressions'. And you need anything that you can access with {$.

    Oh, there's only that workaround:

        $c = "constant";
        return "Twelve in decimal is {$c('c::k')}.";
    

    Which is obviously not much shorter or more readable than just using string concatenation here.

提交回复
热议问题