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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34978828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:18:55  来源:igfitidea点击:

Uncaught ReflectionException: Class log does not exist Laravel 5.2

phplaravelcentos7laravel-5.2

提问by jakehallas

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

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

Uncaught ReflectionException: Class log does not exist

Uncaught ReflectionException: Class log does not exist

I am running Laravel 5.2 on Centos 7.

我在 Centos 7 上运行 Laravel 5.2。

I have seen references to:

我看到了以下参考资料:

  • Removing spaces within the .envfile.
  • Removing the vendor directory & re-installing
  • Removing certain packages required in composer.json
  • 删除.env文件中的空格。
  • 删除供应商目录并重新安装
  • 删除 composer.json 中所需的某些包

I have:

我有:

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

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.

以上都没有给我带来任何快乐。我也在另一台机器上设置了相同的环境,应用程序工作正常。这里唯一的区别是机器(工作)不是从 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

Any help would be much appreciated. Thanks in advance.

任何帮助将非常感激。提前致谢。

回答by jakehallas

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

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

Uncaught ReflectionException: Class log does not exist

Uncaught ReflectionException: Class log does not exist

This exception simply means Laravel tried to log an error but couldn't instantiate Laravel's Logclass. 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 Logclass.

这个异常仅仅意味着 Laravel 试图记录一个错误,但无法实例化 Laravel 的Log类。这不是因为 Log 类四处走动或躲藏。这是因为 Laravel 仍在执行其引导过程并且尚未加载Log该类。

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 Logclass is yet the be loaded. Hence the reason we get a ReflectionException

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

This has occurred in all versions of Laravelthe 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.

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

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

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

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!

我希望这可以帮助别人!

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.

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

回答by Richard Torcato

In your .env file make sure you have no spaces for values

在您的 .env 文件中,确保您的值没有空格

for example this is allowed

例如这是允许的

DB_USERNAME=homestead

this is not allowed

这是不允许的

DB_USERNAME=home stead

you can wrap the value in quotes if you have spaces.

如果有空格,您可以将值括在引号中。

DB_USERNAME="home stead"

really wish they used json for the .env file, maybe we should request that feature

真的希望他们使用 json 作为 .env 文件,也许我们应该请求该功能

回答by Ben Johnson

The underlying error is revealed by modifying vendor/laravel/framework/src/Illuminate/Container/Container.phpand placing the following at the top:

通过修改vendor/laravel/framework/src/Illuminate/Container/Container.php以下内容并将其放置在顶部,可以揭示潜在的错误:

<?php

namespace {
    use Monolog\Logger as Monolog;
    class log extends Illuminate\Log\Writer {
       function __construct()
       {
            $this->monolog = new Monolog("local");
       }
    }
}

//Add curly-braces around the original content, like so:

namespace Illuminate\Container {
    //All original code in this file goes here.

    //...
}

(Credit to https://laracasts.com/discuss/channels/general-discussion/class-log-does-not-exist/replies/160902for this idea.)

(这个想法归功于 https://laracasts.com/discuss/channels/general-discussion/class-log-does-not-exist/replies/160902。)

To add to the list of root-causes for this message, defining a closure in a configuration file andcalling php artisan config:cachesubsequently will cause this (at least in Laravel 5.1). Solution for this manifestation: don't define closures in Laravel configuration files, per https://github.com/laravel/framework/issues/9625.

要添加到此消息的根本原因列表中,在配置文件中定义闭包php artisan config:cache随后调用将导致此问题(至少在 Laravel 5.1 中)。此表现的解决方案:不要根据https://github.com/laravel/framework/issues/9625在 Laravel 配置文件中定义闭包。

回答by Epsilon47

Remove file bootstrap/cache/config.php. This file may not be displayed on windows, if so, use double commander for example. Definitelly will work!

删除文件bootstrap/cache/config.php。此文件可能不会在 Windows 上显示,如果是,请使用双命令器。绝对会奏效!

EDIT:

编辑:

It may be caused by caching .env file, if it's your case, try to remove bootstrap/cache/config.php

这可能是由于缓存 .env 文件引起的,如果是您的情况,请尝试删除 bootstrap/cache/config.php

回答by Ben Fransen

I was noticing the same behavior after adding a few lines to my .env files. Spaces are not allowed without quotes, and so this can be fixed like:

在我的 .env 文件中添加几行后,我注意到了相同的行为。没有引号的空格是不允许的,因此可以像这样修复:

APP_YOUR_NAME="A value with some spaces"

APP_YOUR_NAME="A value with some spaces"

回答by GarryOne

In my case, the missing of PDO extension was the problem. After installing it, the problem was fixed.

就我而言,缺少 PDO 扩展是问题所在。安装后,问题就解决了。

回答by jdkschang

EDIT::

编辑::

Because I wasn't satisfied with the rather clumsy debugging and reworking paths, etc to get the VM running smoothly, I reflected on the process and reinstalled the vagrant box laravel/homestead (virtualbox 1.0.1)

因为我不满足于笨拙的调试和重做路径等让VM顺利运行,我反思了这个过程并重新安装了流浪盒laravel/homestead(virtualbox 1.0.1

For methe issue potentially stemmed from a missing comma in config/app.php. The missing comma likely halted the compilation process and spit out the Uncaught ReflectionException: Class log does not existerror.

对我来说,这个问题可能源于config/app.php. 缺少的逗号可能会停止编译过程并吐出Uncaught ReflectionException: Class log does not exist错误。



This is not a direct answer, but serves more as a guide post to those who venture into this abyss of silent errors

这不是一个直接的答案,而是更多地作为那些冒险进入这个无声错误深渊的人的指南

System: macOS Sierra

系统:macOS Sierra

Vagrant: 1.9.1(Latest Version at time of writing)

流浪者:(1.9.1撰写本文时的最新版本)

VM: laravel/homestead (virtualbox 0.4.0)

虚拟机:laravel/homestead ( virtualbox 0.4.0)

Laravel Version: 5.1.*

Laravel 版本: 5.1.*

PHP: 7.0.*

PHP: 7.0.*



After repeated attempts to resolve the issue which include:

经过反复尝试解决问题,其中包括:

  1. rewriting, removing .env for potential parse issues
  2. php7.1 and the mcrypt / mbstring issues
  3. installing composer suggested packages
  4. updating homestead.rb
  5. PATH related issues
  1. 重写,删除 .env 以解决潜在的解析问题
  2. php7.1 和 mcrypt / mbstring 问题
  3. 安装 Composer 建议的软件包
  4. 更新 homestead.rb
  5. PATH相关问题

Critically, (for me) it seemed it was the virtualbox version in the initial set up:

至关重要的是,(对我而言)它似乎是初始设置中的 virtualbox 版本:

vagrant box add laravel/homestead

vagrant box add laravel/homestead

Instead try supplying the version number like so:

而是尝试像这样提供版本号:

vagrant box add laravel/homestead--box-version 0.4.0

vagrant box add laravel/homestead--box-version 0.4.0



misc:

杂项

I have attempted and failed with the following laravel/homesteadvirtualbox versions:

我尝试过以下laravel/homestead虚拟机版本但失败了:

  • 1.0.1(default)
  • 1.0.1(默认)

and laravel/homestead-7:

laravel/homestead-7

  • 0.2.1
  • 0.2.1

回答by MrMojoRisin

Also this is due to a syntax errorin some file in the conf/ directoryor .env file. In my case I got this error because I forget to put ::classat the end of the line when adding a service provider and facade, to the array providers and alises in conf/app.php file. I corrected this and the error disappeared.

这也是由于conf/ 目录.env 文件中的某些文件中的语法错误造成的。在我的情况下,我收到此错误是因为我在向 conf/app.php 文件中的数组提供者和别名添加服务提供者和外观时忘记将其放在行尾。我更正了这一点,错误消失了。::class

回答by boreasenes

When composer updating, i think laravel makes some validations.

当作曲家更新时,我认为 laravel 会进行一些验证。

  • Install "unzip" package("sudo apt install unzip") if not installed.
  • Check all required extensions such as "mysql", "json", "curl", "xml", "zip", etc. and install("sudo apt install php7.1-mysql") if not installed.
  • Check your file/folder permissions.
  • Check your ".env" file.
  • Check your "config" files.
  • Run "composer update" again.
  • 如果未安装,请安装“unzip”包(“sudo apt install unzip”)。
  • 检查所有必需的扩展名,如“mysql”、“json”、“curl”、“xml”、“zip”等,如果没有安装,请安装(“sudo apt install php7.1-mysql”)。
  • 检查您的文件/文件夹权限。
  • 检查您的“.env”文件。
  • 检查您的“配置”文件。
  • 再次运行“作曲家更新”。

Installing unzip works for me. Good Luck :)

安装 unzip 对我有用。祝你好运 :)

回答by Eduardo Chongkan

I was typing a CMD in the CLI and accidentally typed it in the app config file. I had to follow this procedure in order to find the problem.

我在 CLI 中输入 CMD 时不小心在应用程序配置文件中输入了它。我必须按照这个程序来找出问题所在。

Solution, how to find problem:

解决方法,如何查找问题:

  • make a backup copy of config folder. try to delete one config at a
  • time and try to run composer/artisan command that failed. When you
  • find file that failed - search for a row that can possibly fail.
  • Reason why it is failed is: You use class constant that is not loaded
  • yet. You use class/function that is not loaded yet. etc
  • 制作 config 文件夹的备份副本。尝试删除一个配置
  • 时间并尝试运行失败的 composer/artisan 命令。当你
  • 查找失败的文件 - 搜索可能失败的行。
  • 失败的原因是:您使用了未加载的类常量
  • 然而。您使用尚未加载的类/函数。等等

https://laracasts.com/discuss/channels/general-discussion/class-log-does-not-exist?page=2

https://laracasts.com/discuss/channels/general-discussion/class-log-does-not-exist?page=2