[英]Adding shortcut in PHP Autoload causes conflict on Laravel
I would like to ask you why I'm getting conflict error after added this to composer.json:我想问你为什么在将它添加到 composer.json 后我会收到冲突错误:
"autoload": {
"psr-4": {
"App\\": "app/",
"Models\\": "app/Models/",
"Controllers\\": "app/Http/Controllers/"
},
...
}
and namespace everything inside such as "app\\Models\\People\\Admin.php" be并将其中的所有内容命名为“app\\Models\\People\\Admin.php”
namespace Models\People;
I have searched for this problem before with no luck, did I miss something?我之前搜索过这个问题但没有运气,我错过了什么吗?
Thank you!谢谢!
You are getting this error because the autoloader is including all of the classes under App\\
first, which includes all of the classes under App\\Models
and App\\Controllers
too, then re-including these classes again, which causes this conflict.您收到此错误是因为自动加载器首先包含
App\\
下的所有类,其中也包含App\\Models
和App\\Controllers
下的所有类,然后再次重新包含这些类,这会导致此冲突。
To illustrate this, here is what is happening:为了说明这一点,这里是正在发生的事情:
app
directory.app
目录下的所有类。app/Models/People/Admin.php
and include
s it.app/Models/People/Admin.php
并include
它。app/
, it starts looking for class files under app/Models
, finds the Admin.php
class file and include
s it once more.app/
下的所有类后,它开始在app/Models
下查找类文件,找到Admin.php
类文件并再次include
它。class Admin {}
class Admin {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.