【发布时间】:2017-03-12 05:18:32
【问题描述】:
我是 OOP PHP 的初学者。我有这样的代码
class Index
{
public $activepage = true;
public $url;
public $page;
function __construct()
{
if ($this->activepage) {
$this->url = "Yes";
$this->page = "Home";
} else {
$this->url = "No";
$this->page = "Index";
}
}
public function show()
{
return $this->page;
}
public function showTest()
{
return "test";
}
}
class Home extends Index
{
function __construct()
{
echo $this->show();
}
}
$page = new Home;
我的问题是: 为什么我调用 Home 类时出现空白页?
但是当我像 echo $this->showTest(); 这样更改 Home 类中的构造函数时,它可以工作。并在屏幕上显示“测试”。
我的 show 方法和 Index 类中的 showTest 方法有什么不同?
【问题讨论】:
-
你家的物件是不是已经成熟了?