我的index.php文件容器此代码:
<?php
require 'libs/Bootstrap.php';
$app = new Bootstrap();
和libs / Bootstrap.php文件包含以下代码:
<?php
class Bootstrap {
public function __construct () {
$url = $_GET['url'];
$url = rtrim($url, '/');
$url = explode('/', $url);
// print_r($url);
$file = 'controllers/'.$url[0].'.php';
if(file_exists($file)) {
require_once $file;
echo 2;
} else {
require_once 'controllers/error.php';
$controller = new Error();
return false;
}
echo 3;
$controller = new $url[0];
if(isset($url[2])) {
$controller->{$url[1]}($url[2]);
} else {
if(isset($url[1])) {
$controller->{$url[1]}();
}
}
}
}
Error.php页面
<?php
class Error {
public function __construct () {
echo 'from error class';
}
}
现在访问此URL:http://localhost/practice/mvc/notexist时,它显示一条错误消息:\
Cannot declare class Error, because the name is already in use in D:\xampp\htdocs\practice\mvc\controllers\error.php on line 3
你能告诉我如何解决吗?