0

How could I make string interpolation with constants?

I tried with this code but it seems it not working:

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
    }
}

Is there a way to do string interpolation with constants?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Ali Faris
  • 17,754
  • 10
  • 45
  • 70

0 Answers0