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

damienfa's avatar

Does Laravel catch PHP parse errors in Controllers

In Laravel 4.2 the errors are caught and displayed on a "pretty" page, thanks to Whoops. The error is also logged in the configured log file (by default : /storage/log/... ).

You can be a very good developper but it happens sometimes : you forget a ";", you misspell a php command, a function name (or whatever) in your code. That will throw a "PHP Parse Error". If it happens in the "routes.php" or in any controller of Laravel 4, the pretty Whoops page won't display, and the error won't be logged by Laravel (you have to find the error logged in the default PHP log file of your server).

To reproduce the bug : make a new line in your routes.php with only "let it bug" Save the file. Load a page. (the string "let it bug" isn't a command neither a constant of PHP, so that won't be parsed : PARSE_ERROR !). But, what is your result ? Nothing to display, right ? The error is only reported in the default PHP log file of your server, right ?

Is this behavior normal and happen to you as well ?

Is there a way to make it catch by Laravel ?

0 likes
5 replies
chrisgeary92's avatar

The Whoops page displays fine for me if I make an error in the Controller or routes.php. Just gave it a go, running 4.2 also.


@JeffreyWay - This forum post has broken your forum. The title does not show up

Screenshot

creativeorange's avatar

I cannot reproduce your error by placing some string in the routes file. It might be helpful to give us more information about your environment. Are you using homestead, forge, or something else?

1 like
damienfa's avatar

Thanks for your help,
Nope, I just installed Laravel on my machine, and serve it with an local Apache on "http://localhost:80"

In my conf file (config/app.php) I've set : 'debug' => true.
My routes.php contains only that line :

 <php
Route::get('test', 'gfgzekjfdhzekhfkz');

and when I run "http://localhost:80", I have a pretty Whoops page with the "Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException".
All right.

Now, I make a PARSE_ERROR in my routes.php, like :

 <php
Route::get('test', 'gfgzekjfdhzekhfkz');
Let it bug ! 

Here we are : on "http://localhost:80", I have a blank page ! Nothing new in my app/storage/logs/laravel.log !
But the error have been logged in my default php log file.

When I serve my app with "php artisan serve", I have got a
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException" [...]
on the command line : and that is good !
But on my server, I must use APACHE, and I want that all be logged in the same place (of course, I don't want Whoops on production, but at least I want see bugs logged in the app/storage/logs/laravel.log).

Thanks !

bashy's avatar

500/503 will be Apache based and code errors depending on how PHP is setup. That error will not make it reach Laravel files since it can't parse the file in the PHP compiler.

You will need to install Xdebug or turn on PHP errors.

display_errors = On
error_reporting = E_ALL

Please or to participate in this conversation.