Php PSR-4没有自动加载类文件?
索引:Php PSR-4没有自动加载类文件?,php,Php,索引: 引导: <?php define("START", microtime(true)); define("ROOT", realpath(__DIR__.'/../')); include '../vendor/autoload.php'; include ROOT . '/application/Library/Application.php'; App\Application::getClass('test')->test(); 这一行的问题在于: include
引导:
<?php
define("START", microtime(true));
define("ROOT", realpath(__DIR__.'/../'));
include '../vendor/autoload.php';
include ROOT . '/application/Library/Application.php';
App\Application::getClass('test')->test();
这一行的问题在于:
include ROOT . '/application/Library/Application.php';
我不应该包括它,PSR-4应该为我做。这是我的申请课
<?php
namespace App;
class Application
{
public static function getClass($library){} // removed body for minimal example
}
?>
这是我的文件结构:,供应商文件夹隐藏在我的IDE中,因为我在我的VSCode设置中这样配置它,尽管它在那里。您的PSR-4命名空间说
应用程序命名空间的根位于文件夹应用程序/
,但您的文件位于路径/application/Library/application.php
。使用此配置,您可以将Application.php
移动到/Application/Application.php
,或者将应用程序类的名称空间设置为App\Library
那应该能解决你的问题
<?php
namespace App;
class Application
{
public static function getClass($library){} // removed body for minimal example
}
?>