Laravel 5.5 未找到具有正确命名空间的类

标签 laravel laravel-5 namespaces composer-php autoload

我的 ./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/

相关文章:

php - 从两行中获取每个值的差异

php - 多对多关系在 laravel 中存储和更新

laravel - 为什么 Laravel 中间件会被执行多次?

php - 连接到 tcp ://smtp. mail.yahoo.com:465 超时

c++ - 关于 C++ 未命名命名空间的一些事情

c++ - 如何引用子类中定义的枚举

mysql - Laravel - 使用关系重写此 SQL 查询

php - Laravel php artisan 数据库 :seed leads to "use" statement error

php - 将 Laravel 5 Auth 与自定义表字段名称一起使用?

php - PHP 中的命名空间阻止使用 Yii 静态函数