PHP:尽管自动加载,但仍未找到课程
我正在使用Composer使用PS-4自动加载器。
"autoload": {
"psr-4": {
"App\\":"app/",
"Database\\":"database/"
}
},
因此,我在root目录中具有主要index.php文件。
require 'vendor/autoload.php';
use App\Server;
$server = new Server();
根目录具有应用程序文件夹和一个名为“服务器”类的类,
namespace App;
echo "in server<hr>";
class Server{}
我会得到回声“在服务器中”,因此包含了类文件。但是我得到了这个错误
致命错误:未被发现的错误:class“ app \ server”在/var/www/html/index.php:8 stack trace:#0 {main}扔进/var/www/html/index.php在第8行
上
它寻找一个称为“ app \ server”而不是“服务器”的类。我该如何解决?
I am using the ps-4 autoloader using Composer.
"autoload": {
"psr-4": {
"App\\":"app/",
"Database\\":"database/"
}
},
So, I have the main index.php file in the root directory like this
require 'vendor/autoload.php';
use App\Server;
$server = new Server();
The root directory has the app folder and a class called Server in it like this
namespace App;
echo "in server<hr>";
class Server{}
I get the echo "in server" so the class file gets included. But I get this error
Fatal error: Uncaught Error: Class "App\Server" not found in /var/www/html/index.php:8 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 8
It looks for a class called "App\Server" instead of "Server". How do I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论