我遇到了一个奇怪的问题。在将其上传到我的主机服务器之前,我正在 xampp 服务器上开发我的网站 localhost。我终于完成了我网站的基本组件,这样它就可以加载主页了。一切都按计划进行。
所以我决定将它上传到主机服务器,然后设置 MySQL 凭据,现在它应该可以工作了。嗯..不,它没有。空白页。
所以我戴上手套,开始用随机表达式挖掘代码,
echo 'test';
这样我就可以跟踪发生了什么。它似乎运行得很好,直到is_callable()
被执行。
is_callable()
应该运行__autoload($class)
,所以我尝试了var_dump($class)
它给了我这个结果:
string(11) "Initializer"
string(8) "Database"
string(14) "PageController"
string(14) "BaseController"
string(14) "pcu2phmmr6pam3"
string(14) "pcu2phmmr6pam3"
现在,除了最后两个之外,这里列出的每个类都应该在那里。我不知道那个名字是从哪里来的,因为它不是我在任何地方设置的字符串。
谷歌向我展示的唯一结果pcu2phmmr6pam3
是另一个有类似问题的网站。
现在发生了真正奇怪的事情,我的自动加载函数如下所示:
function __autoload($class) {
var_dump($class);
if (file_exists(ROOT_PATH . DS . 'site' . DS . 'class' . DS . $class . '.class.php')) {
require_once(ROOT_PATH . DS . 'site' . DS . 'class' . DS . $class . '.class.php');
} else if (file_exists(ROOT_PATH . DS . 'site' . DS . 'controller' . DS . $class . '.class.php')) {
require_once(ROOT_PATH . DS . 'site' . DS . 'controller' . DS . $class . '.class.php');
} else if (file_exists(ROOT_PATH . DS . 'site' . DS . 'model' . DS . $class . '.class.php')) {
require_once(ROOT_PATH . DS . 'site' . DS . 'model' . DS . $class . '.class.php');
} else{
throw new Exception('Class `' . $class . '` could not be loaded!');
}
}
它应该加载的每个类都已加载。如果我想创建一个不存在的类,那么它会引发异常。
但是对于pcu2phmmr6pam3
“类”,情况也并非如此。没有抛出异常,现在屏幕上打印了错误,即使我已经设置error_reporting(E_ALL)
这是周围的代码is_callable()
:
$controllerName = ucfirst($this->structure) . 'Controller';
$action = strtolower(((!empty($this->uri[1]))?$this->uri[1]:'index'));
if (is_callable(array($controllerName, $action))) {
$controller = new $controllerName($this->uri, $this->database, $this->structure, $action, $page);
$controller->$action();
} else if (is_callable(array($controllerName, 'index'))) {
$controller = new $controllerName($this->uri, $this->database, $this->structure, 'index', $page);
$controller->index();
} else {
$controller = new NotfoundController($this->uri, $this->database, 'Notfound', 'index', $page);
$controller->index();
}
我可以给你的最后一点信息:
我的 localhost xampp 服务器运行 PHP 5.4.7,我的主机服务器运行 PHP 5.3.20。
解决了,不知道奇怪的类名是如何出现的,如果有人知道,我想知道为什么:)