PHP static variables in double quotes

后端 未结 9 1568
礼貌的吻别
礼貌的吻别 2020-11-29 08:16

How can I get PHP to evaluate a static variable in double quotes?

I want to do something like this:

log("self::$CLASS $METHOD entering");
         


        
9条回答
  •  旧巷少年郎
    2020-11-29 08:37

    Just live with the concatenation. You'd be surprised how inefficient variable interpolation in strings can be.

    And while this could fall under the umbrella of pre-optimization or micro-optimization, I just don't think you actually gain any elegance in this example.

    Personally, if I'm gonna make a tiny optimization of one or the other, and my choices are "faster" and "easier to type" - I'm gonna choose "faster". Because you only type it a few times, but it's probably going to execute thousands of times.

提交回复
热议问题