Composer PSR-4 Autoloading Deprecation: Class Path Mismatch
When executing composer commandsd a class that does not comply with the PSR-4 autoloading standard. This typically occurs when there is a discrepancy between the class's fully qualified name and the path of its corresponding file.The most common cause is a mismatch in the case of the pathname components and the class name. For instance, "foo/bar/Baz.php" does not correspond to "FooBarBaz." Ensure that the case of each name component the coo the cge namespace it represents, such as "Foo/Bar/Baz.php" for "FooBarBaz".
File Name and Class/Namespace Differences
仔細檢查檔案路徑和命名空間之間的匹配情況。有時候,您的類別(或命名空間)可能被命名為FooBar,但它的磁碟路徑卻是"foo-bar"。這種情況也會觸發警告。您需要重新命名檔案或類別(或命名空間)。通常情況下,更改路徑或檔案比更改類別或命名空間名稱更容易,因為更改類別或命名空間名稱需要您重構程式碼以匹配新名稱,而更改路徑則不需要重構任何內容。
巢狀命名空間和缺少聲明
假設您有:並且類Dummy被定義在src/Buzz中:
上述程式碼可以正常運行,但會拋出類似其他情況的警告。正確的做法應該是:您需要不僅對受影響的類別進行更改,還需要對使用或匯入該類別的任何其他檔案進行更改(例如,透過現在聲明use FizzBuzzBuzzDummy;) 。以上是為什麼 Composer 會發出有關類路徑不匹配的 PSR-4 自動載入棄用警告?的詳細內容。更多資訊請關注PHP中文網其他相關文章!