【发布时间】:2013-07-01 16:53:17
【问题描述】:
我是 OOP 的新手,我在学习练习时遇到了这个错误。
Class contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods
错误是从抽象类的子类抛出的,实现了一个接口。我知道抽象类的子类必须实现所有抽象方法,但我没有在父类或接口中声明任何抽象方法。如果我没有在子类中包含来自抽象类或接口的已声明抽象方法,我不应该只收到此错误吗?
子类:
class OuterViewDecorator extends AbstractViewDecorator
{
const DEFAULT_TEMPLATE = "/var/www/portfolio/simple-php/templates/layout.php";
public function render() {
$data["innerview"] = $this->view->render();
return $this->renderTemplate($data);
}
}
父类:
abstract class AbstractViewDecorator implements ViewInterface
{
const DEFAULT_TEMPLATE = "default.php";
protected $template = self::DEFAULT_TEMPLATE;
protected $view;
public function __construct(ViewInterface $view)
{
$this->view = $view;
}
public function render()
{
return $this->view->render();
}
public function renderTemplate(array $data = array())
{
extract($data);
ob_start();
$template = include $this->template;
return ob_get_clean($template);
}
}
界面:
interface ViewInterface
{
public function setTemplate($template);
public function getTemplate();
public function __set($field, $value);
public function __get($field);
public function __isset($field);
public function __unset($field);
public function render();
}
感谢您的帮助
【问题讨论】:
-
从接口中删除 __set __get __isset 和 __unset 方法可能是安全的。
标签: php oop inheritance decorator abstract