我有以下四个 PHP 文件:
1. 单例.php
<?php
class Singleton {
private static $instance = null;
protected function __clone() {}
private function __construct() {}
public static function getInstance() {
if (self::$instance === null) {
self::$instance = new self;
}
return self::$instance;
}
}
?>
2.调试器.php
<?php
interface Debugger {
public function debug($message);
}
?>
3.调试器Echo.php
<?php
require_once 'Singleton.php';
require_once 'Debugger.php';
class DebuggerEcho extends Singleton implements Debugger {
public function debug($message) {
echo $message . PHP_EOL;
}
}
?>
4.TestSingleton.php
<?php
require_once 'DebuggerEcho.php';
$debugger = DebuggerEcho::getInstance();
$debugger->debug('Hello world');
?>
问题是,当我打电话给 line 时$debugger->debug('Hello world')
。我想保留这种结构,但要避免这种(经典)信息:
Call to undefined method Singleton::debug() in TestSingleton.php.
出了什么问题?谢谢你的帮助。