我的 ./app
文件夹看起来像:
+-- app
+-- Classes
+-- Events
+-- EventBase.php
+-- EventX.php
EventX
没什么 secret 文件:<?
namespace App\Classes\Events;
class EventX {
// ...
}
EventBase.php
代表一个外观,在里面我只是尝试实例化一个 EventX
:public function someMethod() {
new \App\Classes\Events\EventX;
// ...
}
在这一行之后,Framework 抛出一个异常,告诉该类未找到:
Symfony\Component\Debug\Exception\FatalThrowableError (E_ERROR)
Class 'App\Classes\Events\EventX' not found
即使:
file_exists(__DIR__ . '\EventX.php'); // true
在尝试创建 Facades 之前,我已经遇到了这个问题,并通过从当前目录移动类文件并移回后解决了这个问题(是的,我不知道为什么,但它有效)。
有人告诉我这是自动加载过程的问题,所以我尝试了这些命令(但仍然无效):
php artisan cache:clear
php artisan clear-compiled
php artisan config:clear
composer dump-autoload
我能做些什么来调查问题?
最佳答案
我认为问题出在 php 标签
<?php
namespace App\Classes\Events;
class EventX {
// ...
}
PHP also allows for short open tag <? (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option).
Link
关于Laravel 5.5 未找到具有正确命名空间的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47531102/