我的简单php类不工作
我写了一个简单的类。但它不起作用。有点不对劲。找不到错误行我的简单php类不工作,php,class,oop,Php,Class,Oop,我写了一个简单的类。但它不起作用。有点不对劲。找不到错误行 class Host { public $scheme; public $hostname; public $www; function __construct(string $scheme,string $hostname,string $www) { $this->scheme = $scheme; $this->hostname = $hostnam
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();
不能将类型提示与标量值一起使用(在您的情况下,
string
-检查)
以这种方式更改构造函数:
public function __construct($scheme, $hostname, $www)
{
$this->scheme = $scheme;
$this->hostname = $hostname;
$this->www = $www;
}
而且应该有效你能详细说明一下“不起作用”吗?你有错误吗?错误的输出?不,我什么都没有白页标量类型暗示?PHP还不支持(除非您已经在运行)另外请注意,get_url()方法将返回
https://wwwgoogle.com
而非https://www.google.com
使用错误报告。将其添加到文件的顶部:错误报告(E\u ALL);ini设置(“显示错误”,1)代码>