【发布时间】:2014-11-12 14:11:48
【问题描述】:
我正在创建一个相互扩展的小型多类系统。可以说 a 类是一个“核心”,并作为检查/管理包装器工作。 b 类是检查$d 是什么,如果存在则调用用户类c 类的方法,否则触发错误返回给a 类。
这是我的代码:
<?php
class a {
private $error;
private $ok;
public function __construct() {
$this->error = array();
$this->ok = array();
// do other stuff here
}
}
class b extends a {
private $head;
private $out;
public function __construct() {
parent::__construct();
global $d;
$this->head = "";
$this->out = "";
if(method_exists($this,$d)) {
$this->{$d}();
} else
$this->error[] = "method '$d' not found";
}
public function output() {
return ($this->head==""?"":'<h1>'.$this->head.'</h1>').$this->out;
}
}
class c extends b {
private $me = "inside c";
public function standard() {
$this->head = "Heading";
$this->out = "it works!";
}
}
$d = "standard";
$c = new c();
echo "<pre>".print_r($c,true)."</pre>";
echo $c->output();
?>
如果我运行 $c->output() 它什么也不返回,但 print_r() 返回这个:
c Object
(
[me:c:private] => inside c
[head:b:private] =>
[out:b:private] =>
[error:a:private] => Array
(
)
[ok:a:private] => Array
(
)
[head] => Heading
[out] => it works!
)
有人可以帮我解决这个问题吗?
【问题讨论】: