Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

freekmurze's avatar

Class log does not exist

When running php artisan on the command line of my mac it fails with this exception:

PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class log does not exist' in /Users/freek/dev/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:776
Stack trace:
#0 /Users/freek/dev/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(776): ReflectionClass->__construct('log')
#1 /Users/freek/dev/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(656): Illuminate\Container\Container->build('log', Array)
#2 /Users/freek/dev/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(644): Illuminate\Container\Container->make('log', Array)
#3 /Users/freek/dev/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(887): Illuminate\Foundation\Application->make('Psr\\Log\\LoggerI...')

Running php artisan in Homestead works just fine. Why could be the reason running that command fails on my mac?

0 likes
73 replies
rikh's avatar

I have a similar problem. My tests all work fine on Vagrant, but when they are run on Scrutinizer as part of a pull request, they fail because they can't find Log::info();

freekmurze's avatar

I found out that this exception get thrown very early when starting the framework. I put an echo in Container.php to find out what is being resolved. On my mac php artisan returns

App\Console\Kernel
Illuminate\Foundation\Bootstrap\DetectEnvironment
Illuminate\Foundation\Bootstrap\LoadConfiguration
App\Exceptions\Handler
log
PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class log does not exist' in /Users/freek/dev/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:778

On homestead everything works fine. These classes are displayed:

App\Console\Kernel
Illuminate\Foundation\Bootstrap\DetectEnvironment
Illuminate\Foundation\Bootstrap\LoadConfiguration
Illuminate\Foundation\Bootstrap\ConfigureLogging
Illuminate\Foundation\Bootstrap\HandleExceptions
Illuminate\Foundation\Bootstrap\RegisterFacades
Illuminate\Foundation\Bootstrap\SetRequestForConsole
Illuminate\Foundation\Bootstrap\RegisterProviders
Illuminate\Foundation\Bootstrap\BootProviders
DaveJamesMiller\Breadcrumbs\Manager
DaveJamesMiller\Breadcrumbs\CurrentRoute
DaveJamesMiller\Breadcrumbs\Generator
DaveJamesMiller\Breadcrumbs\View
Laracasts\Generators\Commands\SeedMakeCommand
Laracasts\Generators\Commands\MigrationMakeCommand
Illuminate\Foundation\Composer
Laracasts\Generators\Commands\PivotMigrationMakeCommand
Illuminate\Console\Scheduling\ScheduleRunCommand
App\Console\Commands\ScheduledBackupCommand
App\Services\ModuleGenerator\Command\GenerateModuleCommand
App\Console\Commands\DeleteOldDraftsCommand
App\Console\Commands\SlackCommand

I'm still puzzled by what causes the error on my mac.

1 like
freekmurze's avatar

Found the error. I got a custom config file with this contents

return [
    'version' => '5.0.2',
    'installDate' => (new DateTime('20150514')),
];

When removing usage of the DateTime-class php artisan runs without problems on my mac. I'm glad I found the source of the problem but I'm puzzled why use DateTime is causing an error.

11 likes
mhh1422's avatar

@freekmurze which file is it? This morning it started to give me the same error and I don't know why!

tomturton's avatar

I struggled with this error today, after upgrading to L5.2, and found it came down to my .env file. The error was thrown because one of the values in this file had spaces. To fix, I just enclosed these values in double quotes.

74 likes
lotyp's avatar

@tomturton Had same issue, your comment helped me to fix it. Problem occurs starting from Laravel 5.2.6

1 like
igaster's avatar

These errors might occure early during Laravel startup because a Facade is used (in our case Log) before it has been loaded in the application Container through its service Provider.... It seems that Laravel 5.2 tries to Log some error beffore the Log class has been initilized yet...

marktimbol's avatar

Removing space character from environment variable value fixed my problem.

4 likes
luizmanoel's avatar

I had the same error . I had a space in the .env file. Surrounding it with quotes fixed the problem. Thanks a lot!

1 like
Thatdoorsajar's avatar

@tomturton yes this was the problem for me too. Thanks for the solution - can you shed any light on to why this was happening. Anyone know why this was happening though!?

gocanto's avatar

@tomturton thanks so much.. I spent 2 days debugging and if it would've been for your solution, I would've been still lacking

OlLis's avatar

Solution, how to find problem:

  1. make a backup copy of config folder.
  2. try to delete one config at a time and try to run composer/artisan command that failed.
  3. When you find file that failed - search for a row that can possible fail. Reason why it is failed is:
  4. You use class constant that is not loaded yet.
  5. You use class/function that is not loaded yet. etc
4 likes
thesunneversets's avatar

Accidentally pasting some garbage into config/app.php will also result in this error, as I just discovered the hard way...

1 like
gocanto's avatar

how can we use trans() helper in a custom config file?

jackbarham's avatar

This also happens if you have a space without quotes around words in the .env file; for example:

Error: WEBSITE_TITLE=Website title - Good: WEBSITE_TITLE="Website title"

roynesh's avatar

my .env has no spaces but I get this error. am using 5.2 and php 7

1 like
Next

Please or to participate in this conversation.