I am currently trying to clone an existing project of mine from github. After clone I run composer install during the process I receive the following error:

Uncaught ReflectionException: Class log does not exist

I am running Laravel 5.2 on Centos 7.

我看到过以下提到:

  • Removing spaces within the .env file.
  • 删除供应商目录&重新安装
  • Removing certain packages required in composer.json

I have:

  • Replaced my .env with the example.env to avoid any custom config errors.
  • 我已删除&重新克隆了回购协议.
  • I have used the default composer.json shipped with Laravel to see if that makes a difference.

以上这些都没有给我带来任何快乐.我还在另一台机器上设置了相同的环境,应用程序运行良好.这里唯一的区别是机器(工作)不是从git克隆的——它是最初的构建环境.

The stack trace I am receiving:

PHP Fatal error:  Uncaught ReflectionException: Class log does not exist in /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php:736
    Stack trace:
    #0 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php(736): ReflectionClass->__construct('log')
    #1 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('log', Array)
    #2 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('log', Array)
    #3 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php(845): Illuminate\Foundation\Application->make('log')
    #4 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php(800): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
    #5 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php(769): Illuminate\Container\Container->getDependenc in /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 736

任何帮助都将不胜感激.提前谢谢您.

推荐答案

Okay, after many hours of digging, the solution for my problem has been found. The reason why I say my problem is because the Exception is very mis-leading.

Uncaught ReflectionException: Class log does not exist

This exception simply means Laravel tried to log an error but couldn't instantiate Laravel's Log class. This is not due to the Log class going walk-abouts or hiding. This is because Laravel is still going through its boot process & has yet to load the Log class.

So, this exception is thrown because an error occurred during the boot cycle of Laravel - when this error occurred it tried to throw an exception - but it can't throw an exception because the Log class is yet the be loaded. Hence the reason we get a ReflectionException

This has occurred in all versions of Laravel the only reason we have seen the exception thrown in laravel 5.1 <= is because previously Laravel silently discarded the problem & carried on through its boot process - basically, your app would still break however you would not receive the Log class exception.

在我的特殊情况下,我没有安装php-mysql扩展,导致Laravel在启动过程中崩溃.

归根结底,调试您可能做错了什么是非常困难的,因为这个错误是非常误导的.

I hope this helps someone!

EDIT: On how to debug this error and find out WHICH missing extension/component is actually causing the problem take a look at @Ben Johnson's answer.

Laravel相关问答推荐

如何让 Laravel 的 Collection 表现得像一个流?

Ziggy 路由默认为查询字符串

从 Laravel 中的值开始主键

在部署到 AWS 时保持我的环境参数安全

Laravel Eloquent 查找日期超过 2 天的行

Laravel 5 将错误发送到Electron邮件

Laravel:使用 Input::old 时 textarea 不会重新填充

如何在 laravel 5.2 中显示 500 内部服务器错误页面?

在 Laravel 中下载后如何重定向?

未定义的类常量App\Providers\RouteServiceProvider::HOME

使用数据库中的值进行动态邮件配置 [Laravel]

将 Laravel .env 变量添加到 Vue 组件

Laravel 动作未定义

如何从 laravel 中的现有数据库创建迁移

在 php Laravel 5 中创建自定义帮助函数的最佳实践是什么?

Laravel 初学者的良好开端

控制器外部的 Laravel 访问请求对象

是否可以将路由参数传递给 Laravel 中的控制器构造函数?

Select,where JSON 包含数组

在哪里放置 Blade::extend