Laravel and the compiled.php file

To be more efficient, Laravel can optimize its files, by putting certain classes in bootstrap/compiled.php to allow the framework to load all of them in one go.

The standard composer.json includes a call to php artisan clear-compiled as a post-update and post-install command, which has the effect of removing this file.

Unfortunately if the updated files are incompatible with the old ones that were just replaced, this can lead to the following error:

Declaration of Illuminate\View\Engines\CompilerEngine::handleViewException() should be compatible with Illuminate\View\Engines\PhpEngine::handleViewException($e) This is because the call to artisan itself is failing: artisan also is loading the framework, which then tries to load compiled.php, but some of the dependent classes or interfaces may have changed. It's a catch-22 : you can't remove the file without loading it, and you need to remove it to load it.

As the file is not essential (Laravel will just load the classes from the vendor directory if it is missing) you can just delete it:

$ rm bootstrap/compiled.php

Another, proper way to fix this is to run php artisan clear-compiled before running composer install or composer update to remove the compiled.php file.

You can add the following to your composer.json in the "scripts" section if you want, to make it automatic:

"pre-install-cmd" :[
    "php artisan clear-compiled"
],
"pre-update-cmd": [
    "php artisan clear-compiled"
],