沃梦达 / 编程问答 / php问题 / 正文

类 FooBarBaz 位于 ./foo/bar/utility/baz.php 不符合 psr-4 自动加载标准.跳过

Class FooBarBaz located in ./foo/bar/utility/baz.php does not comply with psr-4 autoloading standard. Skipping(类 FooBarBaz 位于 ./foo/bar/utility/baz.php 不符合 psr-4 自动加载标准.跳过)

本文介绍了类 FooBarBaz 位于 ./foo/bar/utility/baz.php 不符合 psr-4 自动加载标准.跳过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行composer的updateinstallrequiredump-autoload等时;我突然开始收到一条黄色的弃用通知,上面写着:

When running composer's update, install, require, dump-autoload, etc.; I suddenly start getting a yellow deprecation notice that says:

位于 ./foo/bar/utility/baz.php 的类 FooBarBaz 不符合 psr-4 自动加载标准.跳过.

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

在 Composer 2.0 之前,用于获取:

Before Composer 2.0, one used to get:

弃用通知:位于 ./foo/bar/Baz.php 的类 FooBarBaz 不符合 psr-4 自动加载标准.它不会在 Composer v2.0 中自动加载.在 phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201

Deprecation Notice: Class FooBarBaz located in ./foo/bar/Baz.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201

为什么我会收到此通知或警告?我需要什么来摆脱它并为 Composer 2.0 做好准备?

Why am I getting this notice or warning? What do I need to get rid of it and get ready for Composer 2.0?

推荐答案

发生这种情况的原因有很多.

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.

最常见的原因是,如错误消息所示,Bar.php 的路径名的不同组件的大小写与完全限定类的大小写不匹配姓名;

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.phpAppBarBaz 不匹配.

只需更新您的应用程序或包,以使每个路径组件都匹配它所拥有的命名空间的大小写:

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

FooBarBaz.php

文件名和类名或命名空间的区别

根据命名空间仔细检查路径名.有时你将你的类(或命名空间)命名为 FooBar,但它在磁盘上的路径是foo-bar",例如.或者只是出于任何原因,您的命名空间与文件的路径名不完全匹配.

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.

假设你有:

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

还有类Dummy,定义在inside src/Buzz:

// src/Buzz/Dummy.php
namespace FizzBuzz

class Dummy {}

上述方法可行,但会像其他方法一样抛出通知.正确的做法是:

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

// src/Buzz/Dummy.php
namespace FizzBuzzBuzz

class Dummy {}

您不仅需要对受影响的类进行更改,还需要对使用或导入该类的任何其他文件进行更改.(例如,现在声明 use FizzBuzzBuzzDummy;).

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 FizzBuzzBuzzDummy;).

这篇关于类 FooBarBaz 位于 ./foo/bar/utility/baz.php 不符合 psr-4 自动加载标准.跳过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:类 FooBarBaz 位于 ./foo/bar/utility/baz.php 不符合 psr-4 自动加载标准.跳过