class Host
{
public $scheme;
public $hostname;
public $www;
function __construct(string $scheme,string $hostname,string $www)
{
$this->scheme = $scheme;
$this->hostname = $hostname;
$this->www = $www;
}
public function get_URL()
{
return $this->scheme.'://'.$this->www.$this->hostname;
}
}
$site = new Host('https','google.com','www');
echo $site->get_URL();
答案 0 :(得分:2)
您不能使用带标量值的类型提示(在您的情况下为string
- 请检查docs)
以这种方式更改构造函数:
public function __construct($scheme, $hostname, $www)
{
$this->scheme = $scheme;
$this->hostname = $hostname;
$this->www = $www;
}
它应该有效