Uncaught ReflectionException: Class log does not exist Laravel 5.2

PhpLaravelCentos7Laravel 5.2

Php Problem Overview


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.

I have seen references to:

  • Removing spaces within the .env file.
  • Removing the vendor directory & re-installing
  • Removing certain packages required in composer.json

I have:

  • 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.

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.

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.

Php Solutions


Solution 1 - Php

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.

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!

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.

Solution 2 - Php

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

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

Solution 3 - Php

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

<?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/160902 for this idea.)

To add to the list of root-causes for this message, defining a closure in a configuration file and calling php artisan config:cache subsequently 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 .

Solution 4 - Php

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

EDIT:

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

Solution 5 - Php

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:

APP_YOUR_NAME="A value with some spaces"

Solution 6 - Php

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

Solution 7 - Php

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)

For me the 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 exist error.


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

Vagrant: 1.9.1 (Latest Version at time of writing)

VM: laravel/homestead (virtualbox 0.4.0)

Laravel Version: 5.1.*

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

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

vagrant box add laravel/homestead

Instead try supplying the version number like so:

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


misc:

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

  • 1.0.1 (default)

and laravel/homestead-7:

  • 0.2.1

Solution 8 - Php

Also this is due to a syntax error in some file in the conf/ directory or .env file. In my case I got this error because I forget to put ::class at 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.

Solution 9 - Php

When composer updating, i think laravel makes some validations.

  • 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.

Installing unzip works for me. Good Luck :)

Solution 10 - Php

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.

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

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

Solution 11 - Php

This problem is usually caused by spaces between words in the .env file. Make sure if you have something like

SITE_DESCRIPTION = Social Network for dogs

you replace it with

SITE_DESCRIPTION = 'Social Network for dogs'

Solution 12 - Php

This error may be caused by an error in one of the config files. To locate which file is causing it, change the function loadConfigurationFiles in /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php to:

protected function loadConfigurationFiles(Application $app, RepositoryContract $repository)
{
    foreach ($this->getConfigurationFiles($app) as $key => $path) {
        var_dump('loading key: ' . $key . ' -- path: ' . $path);
        $repository->set($key, require $path);
    }
}

Run php artisan and the last loading "key" is the config file causing the error. Correct it and don't forget to remove the your var_dump command... Good luck.

Solution 13 - Php

I had the same issue and none of the solutions here worked out

I've found that there's an exception of permission denied to config folder

After fixing the permission everything worked!


How to figure it?

Put a break-point in vendor/laravel/framework/src/illluminate/Foundation/Http/Kernel.php

line 101 inside the catch of the handle function.

This is how I've found out about the permission denied.

Solution 14 - Php

Uncaught ReflectionException: Class log does not exist

This Error Comes laravel 5.2 & > versions:

My mistakes are:

Tips1: when You missing (;) end of your code in config File

Other syntax Error This error comes.

My Error code:

<?php
return [
'data' => [
    'common' => [
        'AuthKey1' =>  "17086...........9a87a1",
        'AuthKey2' =>  "17086...........9a87a1",
        'AuthKey3'   =>  "17043...........59969531",
    ],
]
]

Correct code: Missing (;) End of return Array

<?php
return [
'data' => [
    'common' => [
        'AuthKey1' =>  "17086...........9a87a1",
        'AuthKey2' =>  "17086...........9a87a1",
        'AuthKey3'   =>  "17043...........59969531",
    ],
]
];

Solution 15 - Php

Solved this issue after removing space in the .env file (view .env in sublime because vi editor doesn't show space at end of the .env file.) and run below commands.

Commands:

php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan clear-compiled

Solution 16 - Php

In my case, I had used the route() method in a config file. Obviously, this method does not work because these files don't use the Illuminate Helper, they are simple .php with data.

The configuration files are read before instantiating the Log class, which causes the error that Jakehallas explains very well.

Solution 17 - Php

Yes as said by @jakehallas . Its not related to what is showing in exception.

Actually if there is any dababase issue or other config varilables issue causes this.

Actually when i tried to change something in database.php i just duplicated same file as database-copy.php. I didn't execpt this causes issue.

After gone through what i have done before i just removed this database-copy.php file its working fine..

Thanks ...

Solution 18 - Php

I tried a lot of solutions provided here and elsewhere. It did not work for me. I solved it by manually removing /var/www/html/bootstrap/cache/compiled.php and updating the autoload files:

rm /var/www/html/bootstrap/cache/compiled.php
composer dump-autoload

Solution 19 - Php

This type of error when you missed any of the dependencies of your project. Runphp composer.phar update

Solution 20 - Php

Run php artisan config:cache solved it for me.

Or if you are on shared hosting without access to the Terminal/CMD, add this to your Routs.php file:

Route::get('/config-cache', function() {
    Artisan::call('config:cache');
    return '<h1>Config cache cleared successfully</h1>';
});

Then go to yourdomain.com/config-cache to run this script.

Solution 21 - Php

Since no one has mentioned orchestra/testbench yet I thought I'd just add the solution to my problem.

I was writing a Laravel package when I got this error in one of my unit tests. I was using orchestra/testbench to enable testing of Laravel-specific parts of the code.

The problem was simply that the test class was extending PHPUnit\Framework\TestCase instead of Orchestra\Testbench\TestCase.

Solution 22 - Php

I had some negative value like

BUSINESS_RECONCILIATION_DAYS=-8

I needed to wrap

BUSINESS_RECONCILIATION_DAYS="-8"

Solution 23 - Php

In my case, a comma is missing in my config file (config/app.php) after I merged my branch to master.

my code snippet

it was a syntax error, but didn't display it.

Solution 24 - Php

As previous answers has outlined we had an issue with one of our configuration files in laravel. We used the global $app variable which were no longer possible in laravel 5.2+.

The way we found this was to check which file failed to load in the loadConfigurationFiles method in src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php.

Solution 25 - Php

Even this is an old thread, hope my answer could help someone someday (like me). In my case,I found that I should run the artisan from the terminal like so:

sudo php artisan command

That was craching cause it hasn't the permission to write to the log file.

Solution 26 - Php

Just running

composer update

fixed the issue.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjakehallasView Question on Stackoverflow
Solution 1 - PhpjakehallasView Answer on Stackoverflow
Solution 2 - PhpRichard TorcatoView Answer on Stackoverflow
Solution 3 - PhpBen JohnsonView Answer on Stackoverflow
Solution 4 - PhpEpsilon47View Answer on Stackoverflow
Solution 5 - PhpBen FransenView Answer on Stackoverflow
Solution 6 - PhpGarryOneView Answer on Stackoverflow
Solution 7 - PhpjdkschangView Answer on Stackoverflow
Solution 8 - PhpMrMojoRisinView Answer on Stackoverflow
Solution 9 - PhpboreasenesView Answer on Stackoverflow
Solution 10 - PhpEduardo ChongkanView Answer on Stackoverflow
Solution 11 - PhpCengkuru MichaelView Answer on Stackoverflow
Solution 12 - PhpMaxence CupperView Answer on Stackoverflow
Solution 13 - PhpEladView Answer on Stackoverflow
Solution 14 - PhpvenkatskpiView Answer on Stackoverflow
Solution 15 - PhpMuhammad UsamaView Answer on Stackoverflow
Solution 16 - PhpadriarocaView Answer on Stackoverflow
Solution 17 - Phpuser2215155View Answer on Stackoverflow
Solution 18 - PhpJievieView Answer on Stackoverflow
Solution 19 - PhpNimmi VermaView Answer on Stackoverflow
Solution 20 - PhpIdoView Answer on Stackoverflow
Solution 21 - PhpLars NyströmView Answer on Stackoverflow
Solution 22 - PhpAntonio Figueiredo TamuraView Answer on Stackoverflow
Solution 23 - Php严水发View Answer on Stackoverflow
Solution 24 - PhpSimon BengtssonView Answer on Stackoverflow
Solution 25 - PhpMed.ZAIRIView Answer on Stackoverflow
Solution 26 - PhpVadimView Answer on Stackoverflow