Framework: Laravel 5.1+ PHP7 Error - Uncaught ReflectionException: Class log does not exist

Created on 27 Feb 2016  路  7Comments  路  Source: laravel/framework

This is a shameless duplicate of #11724 (which has been locked, otherwise I'd comment there).

There, it was suggested that you:

Mess with the error handler.

In case it saves anyone else some time, what this means is that you need to edit vendor/laravel/laravel/src/Illuminate/Foundation/Http/kernel.php and replace the contents of function reportException($e) with dd($e). You'll now see your error, rather than laravel's failure to log it.

In my case, my MySQL driver config in config/database.php contained a reference to the constant PDO::MYSQL_ATTR_MAX_BUFFER_SIZE which is only available in some builds of PDO.

Most helpful comment

it is very annoying that we can't handle errors

Not even something along these lines (which works for me, based on very limited testing...)

        try {
            $this->app['Illuminate\Contracts\Debug\ExceptionHandler']->report($e);
        } catch (Exception $e) {
            dd($e);
        }

All 7 comments

Reopening for comments.

If I understand correctly:

In PHP 5, these code errors cause fatal PHP errors - and helpful error messages.
In PHP 7, these code errors trigger exceptions, which laravel catches - but fails to handle - hence no helpful error message.

This is a "nofix" atm, sorry. All these issues are caused by user issues each time rather than actual framework bugs though, so it's not critical we fix it.

I definitely agree that it is very annoying that we can't handle errors early in the booting any better.

it is very annoying that we can't handle errors

Not even something along these lines (which works for me, based on very limited testing...)

        try {
            $this->app['Illuminate\Contracts\Debug\ExceptionHandler']->report($e);
        } catch (Exception $e) {
            dd($e);
        }

It's not suitable for production apps though, and could leak information to the user, as well as not showing as an error 500, infact, a 200 OK.

@fisharebest that helped me get to the route of the real problem... in my case, some pieces of cut and paste PHP in an untitled file had somehow saved to config/untitled.php

It would seem to match with other people's experience of having had to remove php functions ( url() etc ) from within config files.

I also came across this error while running a simple artisan command php artisan make list.
@GrahamCampbell what about changing only Console\Kernel.php to

    protected function reportException(Exception $e)
    {
        try {
            $this->app['Illuminate\Contracts\Debug\ExceptionHandler']->report($e);
        } catch (Exception $ex) {
            dd($e);
        }
    }

This way, nothing would be exposed to the user, since only the devs can run console commands. The
Http\Kernel.php would remain the same. In mine opinion this would save a lot of debugging time since those errors usually happen because of having functions in the configuration files instead of giving a message that the log class cannot be found.

Was this page helpful?
0 / 5 - 0 ratings