Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alasudheerkumar's avatar

fileName.php does not comply with psr-4 autoloading standard, Skipping.

Hello @all,

I have been trying to understand what this issue is for almost 2 days and hence need your support to understand.

I am using PHPStorm and I have been using 8.1 and updated to 8.2, with the changes now I am getting a warning saying Class CreateTestTable located in ./database/Migrations/2021_05_03_093750_create_test_table.php doesn't comply with psr-4 autoloading standard.

For Info: I am using the nwidart/laravel-modules(v9) saying that this file is in one of the modules.

here is my composer.json for psr-4 section

 "autoload": {
        "psr-4": {
            "App\": "app/",
            "Modules\": "Modules/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/",
        },
    },

and this is the composer.json in the test module in the directory project/Modules/Test making the directory to root

"autoload": {
        "psr-4": {
            "Modules\Test\": ""
        }
    }

This is an issue as I am not able to install the composer into my modules as necessary.

Can anyone help me to understand this?

0 likes
2 replies
LaryAI's avatar
Level 58

The issue you're encountering is related to the PSR-4 autoloading standard, which requires that the file path and the namespace of the class match. In your case, the class CreateTestTable located in ./database/Migrations/2021_05_03_093750_create_test_table.php does not comply with the PSR-4 autoloading standard because the namespace and the file path do not align correctly.

Here are a few steps to resolve this issue:

  1. Check the Namespace of the Class: Ensure that the namespace declared in your CreateTestTable class matches the directory structure defined in your composer.json.

  2. Update the Namespace in the Class File: Open the 2021_05_03_093750_create_test_table.php file and ensure the namespace is correctly set. For example, if your migrations are under the Modules\Test\Database\Migrations namespace, the file should look like this:

    <?php
    
    namespace Modules\Test\Database\Migrations;
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateTestTable extends Migration
    {
        // Migration methods here
    }
    
  3. Update the composer.json in the Test Module: Ensure that the composer.json in your test module correctly maps the namespace to the directory. It should look something like this:

    "autoload": {
        "psr-4": {
            "Modules\Test\": "src/"
        }
    }
    

    Here, src/ should be the directory where your module's code resides. Adjust this path according to your actual directory structure.

  4. Run composer dump-autoload: After making these changes, run the following command to regenerate the autoload files:

    composer dump-autoload
    
  5. Verify the Directory Structure: Ensure that your directory structure matches the namespace. For example, if your namespace is Modules\Test\Database\Migrations, the directory structure should be:

    project/
    └── Modules/
        └── Test/
            └── src/
                └── Database/
                    └── Migrations/
                        └── 2021_05_03_093750_create_test_table.php
    

By following these steps, you should be able to resolve the PSR-4 autoloading issue. If you still encounter problems, double-check the namespace and directory structure to ensure they are correctly aligned.

alasudheerkumar's avatar

Writing a namespace isn't helping and showing an error "Class name doesn't match the containing file name" it is accepted only when the file name is the same as the class name "CreateTestTable" which an autogenerated migration class won't be.

What should I do??

Please or to participate in this conversation.