SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.33k stars 1.93k forks source link

Psr\SimpleCache\CacheInterface compatibility error #3805

Closed trianity closed 2 years ago

trianity commented 2 years ago

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

What version of Laravel Excel are you using?

3.1.40

What version of Laravel are you using?

9.41.0

What version of PHP are you using?

8.1.12

Describe your issue

Installing mediconesystems/livewire-datatables (latest version) give error related to this package. The error message in the terminal is the following:

` PHP Fatal error: Declaration of Maatwebsite\Excel\Cache\MemoryCache::get($key, $default = null) must be compatible with Psr\SimpleCache\CacheInterface::get(string $key, mixed $default = null): mixed in /path-to-laravel/vendor/maatwebsite/excel/src/Cache/MemoryCache.php on line 62

Symfony\Component\ErrorHandler\Error\FatalError

Declaration of Maatwebsite\Excel\Cache\MemoryCache::get($key, $default = null) must be compatible with Psr\SimpleCache\CacheInterface::get(string $key, mixed $default = null): mixed

at vendor/maatwebsite/excel/src/Cache/MemoryCache.php:62 `

The issue can be handled by adding the necessary return type declarations required by Psr\SimpleCache\CacheInterface .

The related functions in the Cache/MemoryCache.php have {@inheritdoc} type declarations bu tit looks like not enough in PHP 8.1.

How can the issue be reproduced?

Fresh install a Laravel application in PHP 8.1 After Laravel setup run

composer require livewire/livewire

composer require mediconesystems/livewire-datatables

What should be the expected behaviour?

The expected behaviour is installing package without PHP Fatal error, without any issue.

FlowyCoder commented 2 years ago

Hi,

maybe I can help. When I follow your steps it does not work. But the installation instruction says when you insert f.e. "psr/simple-cache": "^2.0" to your composer.json before running composer require mediconesystems/livewire-datatables then it works.

Hope I could help.

BR: Flowy

nickpoulos commented 2 years ago

Yes the extra installation instructions should provide a work around for now.

But having to downgrade a standard PSR library by a full major version is not exactly a fix. This has been an issue since Laravel 9.x, and Laravel 10.x is being released already. Hopefully these issues are planned on being addressed.

FlowyCoder commented 2 years ago

Yeah that's right. I mean there are several fixes as PR but they are all breaking the backwards compatibility.

Let's hope for a fix someday.

warlof commented 2 years ago

Yeah that's right. I mean there are several fixes as PR but they are all breaking the backwards compatibility.

Let's hope for a fix someday.

Why not releasing a major version which avoid backwards compatibility and meet with new standards ? At some point, there are no choice but to break things - PHP engine had change its core class :/

trianity commented 2 years ago

Why not releasing a major version which avoid backwards compatibility and meet with new standards ? At some point, there are no choice but to break things - PHP engine had change its core class :/

I think that would be the solution. PHP 8.1 does not provide backward compatibility, so a major release with a new version number is justified.

patrickbrouwers commented 2 years ago

As explained in a lot of other issues about this problem, we can't merge any of the breaking changes PR's as we are currently still maintaining the same version for a lot of older Laravel and PHP versions. For now this change is planned for the next major release.