Class constant in a string in PHP

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

    It's a little cryptic, but there is a note on this in the manual.

    Functions, method calls, static class variables, and class constants inside {$} work since PHP 5. However, the value accessed will be interpreted as the name of a variable in the scope in which the string is defined. Using single curly braces ({}) will not work for accessing the return values of functions or methods or the values of class constants or static class variables.

    The last sentence tells you it won't work so yes, concatenation is the way to go here.


    (modified) Example of above paragraph:

提交回复
热议问题