PHP Composer Autoloader类未找到异常
发布时间:2020-12-13 13:45:13 所属栏目:PHP教程 来源:网络整理
导读:标题说明了自己.所以这是我的项目结构: |src |Database |Core |MySQL.php |Support start.php|vendorcomposer.jsonindex.php MySQL.php文件: ?phpnamespace DatabaseCore;//Some methods here index.php和start.php文件: //start.php file?phprequire __
标题说明了自己.所以这是我的项目结构:
|src |Database |Core |MySQL.php |Support start.php |vendor composer.json index.php MySQL.php文件: <?php namespace DatabaseCore; //Some methods here index.php和start.php文件: //start.php file <?php require __DIR__ . '/../vendor/autoload.php'; ?> //index.php file <?php use DatabaseCore; require __DIR__ . '/src/start.php'; $mysql = new MySQL(); // Gets exception Class 'MySQL' cannot found etc. ?> 最后我的composer.json自动加载部分: "autoload": { "psr-4": "Database": "src/" // Also tried "src/Database" too } 问题出在哪儿?我真的厌倦了试图应对这种情况.请帮帮我们!谢谢.
初始化类时需要包含命名空间:
$mysql = new DatabaseCoreMySQL(); 要么 use DatabaseCoreMySQL; $mysql = new MySQL(); 见Using namespaces: Aliasing/Importing (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |