Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer Update with Laravel 5.4 & PHP 7 "Class Name must be a valid object or a string"

So there are a few threads on this but none with exactly the same issue. Basically I upgraded to php 5.4 from 5.1 and php 7 from 5.6 and I am now getting this error message.

PHP Fatal error:  Uncaught Error: Class name must be a valid object or a string in /var/www/dev1/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:96

The reason this seems weird to me is the error is in the actual laravel files not in my app / something I have edited. This error happens when I run composer update or whenever I try and visit any of my webpages. Below is a full dump from composer update, any ideas?

[root@dev1 dev1]# composer update
> php artisan clear-compiled
PHP Fatal error:  Uncaught Error: Class name must be a valid object or a string in /var/www/dev1/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:96
Stack trace:
#0 [internal function]: Illuminate\Foundation\Exceptions\Handler->Illuminate\Foundation\Exceptions\{closure}(0, 'Symfony\\Compone...')
#1 /var/www/dev1/bootstrap/cache/compiled.php(6207): call_user_func(Object(Closure), 0, 'Symfony\\Compone...')
#2 /var/www/dev1/bootstrap/cache/compiled.php(12223): Illuminate\Support\Arr::first(Array, Object(Closure), NULL)
#3 /var/www/dev1/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(97): Illuminate\Support\Collection->first(Object(Closure))
#4 /var/www/dev1/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(61): Illuminate\Foundation\Exceptions\Handler->shouldntReport(Object(ReflectionException))
#5 /var/www/dev1/app/Exceptions/Handler.php(33): Illuminate\Foundation\Exceptions\Handler->report(Object(ReflectionException))
#6 /var/www/dev1/vendor/laravel/fram in /var/www/dev1/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 96
Script php artisan clear-compiled handling the pre-update-cmd event returned with error code 255
like image 599
CMOS Avatar asked Mar 10 '17 21:03

CMOS


People also ask

Does laravel 8 support php7?

Laravel 8 requires PHP 7.3+ or above so you need this version or the latest version of PHP installed on your system.

Which PHP version is required for laravel 9?

Laravel 9.x requires a minimum PHP version of 8.0.


1 Answers

I've got a similar error when upgrading to Laravel 5.4. The problem is that Laravel is still loading bootstrap/cache/compiled.php (even though it says it's not used by the framework anymore). Removing the file will solve your issue.

From the docs:

If it exists, you may delete the bootstrap/cache/compiled.php file. It is no longer used by the framework.

like image 191
Marwelln Avatar answered Oct 16 '22 16:10

Marwelln