我有带有库的 Laravel Composer 文件:
"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 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
如果我安装
"psr/simple-cache": "2.0"
,它就会工作,但为什么在 10 台计算机中它可以与自动安装的 "psr/simple-cache": "3.0"
一起使用,而只有在 1 台服务器中我才可以使用此库。
功能对比:
<?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;
它与我们在内存缓存中的所有内容相同:
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;
}
安装后运行脚本时发生了一些事情,并且出现错误
如果运行就可以正常工作
composer update --no-script
但无论如何,稍后我需要转储自动加载,我会得到同样的错误。
它如何解析这个简单的缓存并得到错误的函数
PsrExt\SimpleCache\CacheInterface::get($key, $default = <default>)
,如果它确实安装了类型,那么它如何在其他服务器上正常工作?
PHP更新到8.1.21版本,也尝试更新composer,清理composer缓存,删除供应商,但没有帮助。
尝试了不同的 PHP 版本,它可以在 8.1.9 中运行,但即使更新到最后的 8.1.21 也没有帮助。
尝试安装,尝试更新,尝试使用锁定文件和不使用锁定文件,都是相同的错误。
终于,我发现了问题所在。问题出在服务器上安装的
php-psr
模块。该模块有自己的 PSR simple CacheInterface
实现,Composer 正在比较模块中的功能,而不是供应商文件夹中安装的功能。
从服务器中删除
php-psr
模块后,一切又开始正常工作。
移除内置psr模块。 使用
apt remove php-psr
或 dnf remove php-psr
之后不要忘记重新启动您的网络服务器(apache 或 php-fpm)。