laravel 如何使用消息“类日志不存在”修复未捕获的异常“ReflectionException”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38419182/
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-09-14 14:10:22  来源:igfitidea点击:

How to fix Uncaught exception 'ReflectionException' with message 'Class log does not exist'?

phplaravelcomposer-phpwindows-server-2012-r2

提问by Waqleh

I am facing an issue with composer on Windows Server 20012 R2. I am trying to deploy a website and every time I run composer installor composer updateI get the following:

我在Windows Server 20012 R2上遇到了Composer的问题。我正在尝试部署一个网站,每次运行composer installcomposer update得到以下信息时:

$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize
Script php artisan optimize handling the post-install-cmd event returned with an error


  [RuntimeException]
  Error Output:


install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...

And when I checked the php error logI find the following:

当我检查php 错误日志时,我发现以下内容:

[17-Jul-2016 08:04:58 UTC] PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class log does not exist' in C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php:734
Stack trace:
#0 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php(734): ReflectionClass->__construct('log')
#1 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Container\Container->build('log', Array)
#2 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(697): Illuminate\Container\Container->make('log', Array)
#3 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php(849): Illuminate\Foundation\Application->make('Psr\Log\LoggerI...')
#4 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\ in C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 734

When I try the same project on an Ubuntu servereverything works fin! I have tried every answer i could find on the internet, but nothing worked for me. Any advise on how to solve this? And why it is happening?

当我在Ubuntu 服务器上尝试同一个项目时,一切正常!我已经尝试了我可以在互联网上找到的所有答案,但没有任何对我有用。关于如何解决这个问题的任何建议?为什么会发生?

The windows server PHP version is 5.6.

Windows Server PHP 版本为 5.6。

composer.jsonfile:

composer.json文件:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "intervention/image": "^2.3",
        "greggilbert/recaptcha": "2.*",
        "laravelcollective/html": "5.2.*",
        "vsch/laravel-translation-manager": "*"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "symfony/css-selector": "2.8.*|3.0.*",
        "symfony/dom-crawler": "2.8.*|3.0.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\": "app/"
        },
         "files": ["app/Http/Helpers/helpers.php"]
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\Foundation\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\Foundation\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

回答by Waqleh

I was able to fix this issue by removing any space in the values in the .envfile e.g.:

我能够通过删除.env文件中值中的任何空格来解决这个问题,例如:

MAIL_PORT= 587
MAIL_FROM_NAME=ABC Medical

to:

到:

MAIL_PORT=587
MAIL_FROM_NAME=ABCMedical

Or by using quotes:

或者使用引号:

MAIL_PORT=587
MAIL_FROM_NAME="ABC Medical"

回答by Rafael Miranda

I got this error when passing values with spaces in .envwithout quotes, I fixed it by wrapping the values in quotes.

我在传递带空格.env而不带引号的值时遇到此错误,我通过将值括在引号中来修复它。

回答by Hanson

have you try composer dump-autoload?

你试过 composer dump-autoload吗?

you might add a class without dump-autoload

你可以添加一个没有 dump-autoload 的类

回答by mbarie

Most common reasons I can think of for this error to occur are the following:

我能想到的导致此错误发生的最常见原因如下:

  1. Log class is called in a scope where it is not included with the USE statement.
  2. A config file contains (parse) errors, which in turn does not allow your application to find the Log class. Check the files loaded early on in Laravel such as app.php.
  1. Log 类在不包含在 USE 语句中的范围内被调用。
  2. 配置文件包含(解析)错误,这反过来又不允许您的应用程序找到 Log 类。检查 Laravel 中早期加载的文件,例如 app.php。