如何使用常量进行字符串插值
我尝试使用此代码,但似乎无效
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
}
}
有没有办法用常量进行字符串插值?