PHP:尽管自动加载,但仍未找到课程

发布于 2025-01-25 09:04:15 字数 637 浏览 3 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文