php中常量的字符串插值

时间:2018-02-03 19:43:54

标签: php string-interpolation

如何使用常量进行字符串插值

我尝试使用此代码,但似乎无效

class DB{

    const DBNAME = "test";
    private $host = "localhost";

    public function __construct(){
        $connectionString = "dbname={DB::DBNAME}";     //with will not work
        $connectionString = "host={$this->host}";      //no problem with this
    }

}

有没有办法用常量进行字符串插值?

0 个答案:

没有答案