Class 在 Linux 中使用 PSR-4 Autoload 时未找到,在 Windows 中有效

Class not found when using PSR-4 Autoload in Linux, works in Windows

简介

您好, 我将我的文件从我的本地电脑 运行 WAMP 移动到我的网络服务器,这是一台 Linux 机器。
我与 composer 合作,使用其自动加载功能来加载我的 MVC 结构,稍后会详细介绍。

我在网页上收到的错误如下:
Fatal error: Uncaught Error: Class 'App\Model\DB' not found in <folder_structure>/config/_boot.php:15

我的 Windows 机器上没有这个错误,代码在那里工作得很好。

文件夹结构

我使用相同的文件夹结构,(简化)如下:

- config
-- _boot.php
- dist
-- index.php
-- includes
--- header.php
- src
-- app
--- Models
---- db.php
- composer.json

代码部分

我的 config/_boot.php 文件如下所示:

use App\Model\DB;
...
$db = new DB($database['host'], $database['dbname'], $database['user'], $database['password']);

我的 src/app/Model/db.php 文件如下所示:

namespace App\Model;
class DB
{
}

我的 composer.json 包含这个:

"autoload": {
        "psr-4": {
            "App\": "src/app/"
        },
        "files": [
            "src/app/functions.inc.php",
            "config/_boot.php",
            "src/app/Routing.php"
        ]
    }

autoload_psr4.php

return array(
    ...
    'App\' => array($baseDir . '/src/app'),
    ...
);

问题

有没有人知道我做错了什么?

我尝试过/检查过的事情

PS: 这是我在 Whosebug 上的第一个问题,欢迎改进布局的提示...

PSR-4 状态:

The terminating class name corresponds to a file name ending in .php. The file name MUST match the case of the terminating class name.

您将 DB class 放入 db.php 文件,违反了这条规则。它适用于 Windows 而不是 Linux 的原因是后者是关于文件和文件夹名称的 case-sensitive。

因此解决方法是将 db.php 重命名为 DB.php