Framework: ReflectionException gets rendered twice

Created on 4 Oct 2016  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 5.3.16
  • PHP Version: 5.6.15
  • Database Driver & Version: None / Not Relevant

    Description:

When a controller does not exist, a _ReflectionException_ is fired.
Somewhere in the rendering process for this exception the corresponding HTTP response gets output twice.

This is especially bad if the error response contains JSON as this results as the JSON string "doubled", which results in invalid syntax.

Steps To Reproduce:

  1. Create a fresh Laravel project, no database required.
  2. Go to your _web.php_ routes file and add the following line:
    Route::get('/test', 'TestController@index');
    This controller obviously doesn't exist and therefore will trigger the expected ReflectionExpection.
  3. Serve up the project using php artisan serve.
  4. Navigate in your browser to localhost:8000/test and take a look at the rendered exceptions (should be only one, it gets rendered twice).

    My Observations:

  • Take a look at the current/total count on the rendered exception. The total count is 1, but still 2 are displayed. Screenshot
  • If you comment out either
    $response->send(); or $kernel->terminate($request, $response);
    in your _public/index.php_ the duplication stops and the exception is rendered once only.
    My guess would be that both of them are somehow handling the exception instead of just one.

All 3 comments

Probably because the exception occurred again when the view was rendered.

I got the same thing here. Also found an open thread with the same behavior in https://laracasts.com/discuss/channels/laravel/exception-handler-fired-multiple-times .

Does anyone know the solution?

Probably because the exception occurred again when the view was rendered.

Why the downvotes? That's basically exactly the problem in most cases, and the most common case affecting controller middlewares has been fixed in laravel 5.4.

Was this page helpful?
0 / 5 - 0 ratings