沃梦达 / 编程问答 / php问题 / 正文

未捕获的 ReflectionException:Laravel 5.2 中不存在类日

Uncaught ReflectionException: Class log does not exist Laravel 5.2(未捕获的 ReflectionException:Laravel 5.2 中不存在类日志)

本文介绍了未捕获的 ReflectionException:Laravel 5.2 中不存在类日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试从 github 克隆我的现有项目.克隆后,我在此过程中运行 composer install 收到以下错误:

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:

未捕获的反射异常:类日志不存在

我在 Centos 7 上运行 Laravel 5.2.

I am running Laravel 5.2 on Centos 7.

我看到了对以下内容的引用:

I have seen references to:

  • 删除 .env 文件中的空格.
  • 删除供应商目录 &重新安装
  • 删除 composer.json 中所需的某些包

我有:

  • example.env 替换我的 .env 以避免任何自定义配置错误.
  • 我已删除 &重新克隆了 repo.
  • 我使用了 Laravel 附带的默认 composer.json 来查看这是否有所不同.
  • Replaced my .env with the example.env to avoid any custom config errors.
  • I have removed & re-cloned the repo.
  • I have used the default composer.json shipped with Laravel to see if that makes a difference.

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

None of the above have brought me any joy. I also have the same environment set up on another machine with the application working fine. The only difference here is the machine (working) wasn't cloned from git - it was the initial build environment.

我收到的堆栈跟踪:

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): IlluminateContainerContainer->build('log', Array)
    #2 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): IlluminateContainerContainer->make('log', Array)
    #3 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php(845): IlluminateFoundationApplication->make('log')
    #4 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php(800): IlluminateContainerContainer->resolveClass(Object(ReflectionParameter))
    #5 /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php(769): IlluminateContainerContainer->getDependenc in /var/www/html/Acme/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 736

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

Any help would be much appreciated. Thanks in advance.

推荐答案

好吧,经过几个小时的挖掘,我的问题的解决方案已经找到了.我之所以说我的问题是因为 Exception 非常具有误导性.

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.

未捕获的反射异常:类日志不存在

这个异常仅仅意味着 Laravel 试图记录一个错误,但无法实例化 Laravel 的 Log 类.这不是因为 Log 类四处走动或躲藏.这是因为 Laravel 仍在经历其启动过程 &尚未加载 Log 类.

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.

所以,抛出这个异常是因为在 Laravel 的启动周期中发生了错误——当这个错误发生时它试图抛出一个异常——但是它不能抛出异常,因为 Log 类尚未加载.因此我们得到一个 ReflectionException

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

这个在所有版本的 Laravel 中都发生过 我们在 Laravel 5.1 中看到抛出异常的唯一原因 <= 是因为之前 Laravel 默默地丢弃了这个问题 &通过其启动过程进行 - 基本上,您的应用程序仍然会中断,但您不会收到 Log class exception.

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 在启动过程中中断.

In my particular case I didn't have the php-mysql extension installed causing Laravel to break during its boot process.

最终,由于错误非常具有误导性,因此调试您可能做错的事情非常困难.

Ultimately, it is incredibly difficult to debug what you may have done wrong due to the error been very mis-leading.

我希望这对某人有所帮助!

I hope this helps someone!

关于如何调试此错误并找出缺少的扩展/组件实际上是导致问题的原因,请查看@Ben Johnson 的回答.

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.

这篇关于未捕获的 ReflectionException:Laravel 5.2 中不存在类日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:未捕获的 ReflectionException:Laravel 5.2 中不存在类日

基础教程推荐