Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP deferred string interpolation

Is there a way to 'prepare' a string for later interpolation (without using custom expansion function)?
For instance:

class Test {
    private static $STR_VAL = "the val is $v";

    public static function printVal($v) {
        echo self::$STR_VAL;
    }
}
like image 882
mkvcvc Avatar asked Feb 20 '23 22:02

mkvcvc


1 Answers

sprintf()

class Test {
    private static $STR_VAL = "the val is %s";

    public static function printVal($v) {
        echo sprintf(self::$STR_VAL, $v);
    }
}
like image 142
KingCrunch Avatar answered Feb 28 '23 13:02

KingCrunch