【发布时间】:2016-10-02 05:21:12
【问题描述】:
我刚刚写了这样的代码:
<?php
class test
{
// Force Extending class to define this method
abstract protected function getValue();
abstract protected function prefixValue($prefix);
// Common method
public function printOut() {
print $this->getValue() . "\n";
}
}
class testabs extends test{
public function getValue()
{
}
public function prefixValue($f)
{
}
}
$obj = new testabs();
?>
当我运行此代码时,我收到以下错误:
致命错误:类 test 包含 2 个抽象方法,因此必须在 C:\wamp64\www\study 中声明为抽象或实现其余方法(test::getValue, test::prefixValue) \abstract.php 第 12 行
我了解此错误的第一部分。我将类测试更改为抽象并且错误消失了,但or 部分我无法理解。
【问题讨论】:
-
or 部分是从类扩展您的
test类的角度来看的。它是双向的;要么使您的test类抽象或使任何其他扩展test的类抽象,因为它们不实现任何继承的抽象声明。