Laravel 5.1: Unable to override Illuminate \\ Contracts \\ Support \\ Arrayable class

In the Laravel 5 application, an error message appears:

PHP Fatal error:  Cannot redeclare class Illuminate\\Contracts\\Support\\Arrayable in /var/www/.../bootstrap/cache/compiled.php on line 156

This error occurs only in my staging environment, and not on my local website. I would like to publish more information, but I do not have it. Because I do not know where this error is caused.

If I delete the file (cache / compiled.php), everything works fine. But after each deployment, the same error occurs. Everything works fine on my localhost.

My question is: does anyone know where to look, because I'm out of ideas.

+4
source share
4 answers

.
cache/compiled.php

php artisan clear-compiled
+4

, , :

https://sentinelstand.com/article/laravel-5-optimization-commands

, , bootstrap/cache/compiled.php. , bootstrap/autoload.php, , , . compiled.php, - autoload.php autoload.php.

PSR4 composer.json. , . ( : Laravel 3, , : -).

, -, , artisan optimize bootstrap/cache/compiled.php, --force , , , , / , .. p >

, , :

  • artisan config:cache
  • artisan optimize
  • rm bootstrap/cache/compiled
  • , .

, bootstrap/cache/services.json, , artisan clear-compiled . , , bootstrap/cache/compiled.php , , , - .

, compiled.php, artisan optimize Laravel 5.1, Laravel 5.4, , , PHP 7 , , /, . OPcache - .

+1

, .

helpers.php laravel. , , composer.json. - Collection (\Illuminate\Support\Collection::macro(...)).

helpers.php , Illuminate\Support\Collection. , , Illuminate\Contracts\Support\Arrayable. , cache/compiled.php. Boom.

: .

/autoload.php:

$compiledPath = __DIR__.'/cache/compiled.php';

if (file_exists($compiledPath)) {
   require $compiledPath;
}

require __DIR__.'/../vendor/autoload.php';

. , , , .

0

The problem is the artisan team optimize. If you delete the compiled.php file and then do not run optimizeit should work.

-1
source

Source: https://habr.com/ru/post/1608452/


All Articles