Composer install error "Declaration of Maatwebsite\Excel\Cache\MemoryCache::get(string $key, mixed $default = null)"

huangapple go评论74阅读模式
英文:

Composer install error "Declaration of Maatwebsite\Excel\Cache\MemoryCache::get(string $key, mixed $default = null)"

问题

我有一个带有库的Laravel组合器文件:

"require": {
"php": "^8.1",
"ext-intl": "",
"ext-openssl": "
",
"ext-zip": "*",
"arielmejiadev/larapex-charts": "^5.2",
"barryvdh/laravel-dompdf": "^2.0",
"diglactic/laravel-breadcrumbs": "^7.1",
"doctrine/dbal": "^3.1",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/validation": "^3.2",
"jorijn/laravel-security-checker": "^2.3",
"kwn/number-to-words": "^2.4",
"laravel/framework": "^v9.0",
"laravel/tinker": "^2.5",
"league/oauth2-facebook": "^2.2",
"maatwebsite/excel": "^3.1",
"madorin/matex": "^1.0",
"pbmedia/laravel-ffmpeg": "^8.1",
"phpoffice/phpspreadsheet": "^1.22",
"revolution/laravel-google-sheets": "^6.0",
"spatie/laravel-activitylog": "^4.5",
"spatie/laravel-sql-commenter": "^1.2"
},


在本地和其他两台服务器上运行良好,但在一台服务器上安装时出现错误:

`PHP致命错误:在/var/www/html/livepartners_v3.com/vendor/maatwebsite/excel/src/Cache/MemoryCache.php的第62行中,Maatwebsite\Excel\Cache\MemoryCache::get(string $key, mixed $default = null):mixed必须与PsrExt\SimpleCache\CacheInterface::get($key, $default = <default>)兼容的声明`

如果我安装`"psr/simple-cache": "2.0"`,它将工作,但为什么在10台计算机上自动安装了`"psr/simple-cache": "3.0"`,只有在1台服务器上我遇到了与此库的问题。

比较的功能:

has($key)) {
return $this->cache[$key];
}

return $default;
}
```

当运行安装后的脚本时会发生一些事情,我会收到错误。

如果运行`composer update --no-script`,它将正常工作,但无论如何以后我都需要dump-autoload,我将会得到相同的错误。

它是如何解析这个简单的缓存并获取错误的函数`PsrExt\SimpleCache\CacheInterface::get($key, $default = )`,而没有任何类型,如果它确实安装了带有类型,并且它在其他服务器上运行良好?

PHP更新为8.1.21版本,也尝试过更新composer、清理composer缓存、删除vendor,都没有帮助。

尝试了不同的PHP版本,8.1.9中可以工作,但甚至更新到最新的8.1.21也无济于事。

尝试安装,尝试更新,尝试带锁文件和不带锁文件都是相同的错误。
```

英文:

I have laravel composer file with libs:

```
"require": {
"php": "^8.1",
"ext-intl": "*",
"ext-openssl": "*",
"ext-zip": "*",
"arielmejiadev/larapex-charts": "^5.2",
"barryvdh/laravel-dompdf": "^2.0",
"diglactic/laravel-breadcrumbs": "^7.1",
"doctrine/dbal": "^3.1",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/validation": "^3.2",
"jorijn/laravel-security-checker": "^2.3",
"kwn/number-to-words": "^2.4",
"laravel/framework": "^v9.0",
"laravel/tinker": "^2.5",
"league/oauth2-facebook": "^2.2",
"maatwebsite/excel": "^3.1",
"madorin/matex": "^1.0",
"pbmedia/laravel-ffmpeg": "^8.1",
"phpoffice/phpspreadsheet": "^1.22",
"revolution/laravel-google-sheets": "^6.0",
"spatie/laravel-activitylog": "^4.5",
"spatie/laravel-sql-commenter": "^1.2"
},
```
It works fine on local, and two other servers, but on one server we have error during instalation:

`PHP Fatal error: Declaration of Maatwebsite\Excel\Cache\MemoryCache::get(string $key, mixed $default = null): mixed must be compatible with PsrExt\SimpleCache\CacheInterface::get($key, $default = <default>) in /var/www/html/livepartners_v3.com/vendor/maatwebsite/excel/src/Cache/MemoryCache.php on line 62`

If I install `"psr/simple-cache": "2.0"`, it will work, but why in 10 computers it works with `"psr/simple-cache": "3.0"` installed automaticaly and only in 1 server I have this issee with this lib.

Compared functions:

```
<?php

namespace Psr\SimpleCache;

interface CacheInterface
{
/**
* Fetches a value from the cache.
*
* @param string $key The unique key of this item in the cache.
* @param mixed $default Default value to return if the key does not exist.
*
* @return mixed The value of the item from the cache, or $default in case of cache miss.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function get(string $key, mixed $default = null): mixed;
```
It is the same everything as we have in Memory cache:

```

namespace Maatwebsite\Excel\Cache;

use Psr\SimpleCache\CacheInterface;

class MemoryCache implements CacheInterface

public function get(string $key, mixed $default = null): mixed
{
if ($this->has($key)) {
return $this->cache[$key];
}

return $default;
}
```
Something happens when it runs scripts after installing and I get error

It works fine if run `composer update --no-script`
but anyway later I need dump-autoload and I will get the same error.

How it parse this simple cache and get wrong function `PsrExt\SimpleCache\CacheInterface::get($key, $default = <default>)` without any types if it is realy installed with types and how it works fine on other servers?

PHP updated to 8.1.21 version, also tried to update composer, clean composer cache, remove vendor, doesn't help.

Tried different PHP versions, it works in 8.1.9, but even update to last 8.1.21 doesn't help.

Tried install, tried update, tried with lock file and without lock files all the same error.

# 答案1
**得分**: 1

最后,我找到了问题所在。问题出在服务器上安装的 `php-psr` 模块上。这个模块有自己的实现方式,用于 PSR 简单的 `CacheInterface`,而 Composer 正在比较模块中的函数,而不是安装在供应商文件夹中的函数。

在从服务器上移除 `php-psr` 模块之后,一切都重新正常工作了。

英文:

Finally, I identified the issue. The problem was with the `php-psr` module installed on the server. This module had its own implementation of the PSR simple `CacheInterface`, and Composer was comparing the function in the module instead of the one installed in the vendor folder.

After removing the `php-psr` module from the server, everything started working fine again.

huangapple
  • 本文由 发表于 2023年7月7日 00:21:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76630801.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定