Class Foo\Bar\Baz located in ./foo/bar/utility/baz.php does not comply with psr-4 autoloading standard. Skipping

This can happen for a variety of reasons.

The important thing is to pay attention to the error message which generally points very accurately to the source of the issue.

Path Case

The most common reason for this is that, as shown in the error message, the case for the different components of the pathname for Bar.php do not match with the case for the fully qualified class name;

foo/bar/Baz.php does not match App\Bar\Baz.

Simply update your application or package so that each path component matches the case of its the namespace it holds:

Foo\Bar\Baz.php

File name and Class name or Namespace differences

Check the pathname against the namespace very carefully. Sometimes your named your class (or your namespace) FooBar, but its path on disk is “foo-bar”, for example. Or simply for any reason your namespace does not fully match the pathname of the files.

This will trigger a notice/warning as well. You need to either rename the files or rename the classes (or namespaces).

Usually, changing the path or files is much easier, since changing the class or namespace names would require you refactor code to match the new names, whereas changing the paths will not need you to refactor anything.

Nested namespaces and missing declaration

Let’s say that you have:

"autoload": {
        "psr-4": {
            "Fizz\\Buzz\\": "src/"
        }
    },

And the class Dummy, defined inside src/Buzz:

// src/Buzz/Dummy.php
namespace Fizz\Buzz

class Dummy {}

The above will work, but will throw the notice like the others. The correct way would be:

// src/Buzz/Dummy.php
namespace Fizz\Buzz\Buzz

class Dummy {}

You’ll need not only to make the change on the affected class, but on any other file where this class is used or imported. (e.g. by now declaring use Fizz\Buzz\Buzz\Dummy;).

Leave a Comment