前情:我们框架使用的TP6.0,由于我的开发环境和线上的PHP版本不一致,在使用生产环境代码在我的开发环境上部署执行时遇到框架报错和Composer报错,这里分享给大家。大家可能说,你把PHP版本更新可不就行了嘛,大家说的对,但是就是因为有各种原因没办法更新,我还很急用,所以就只能就近先解决composer的问题,分享给大家。
问题一:
执行Composer报错:
PHP Fatal error: Declaration of think\Container::has($name) must be compatible with Psr\Container\ContainerInterface::has(string $id) in /data/wwwroot/yzbackproject/php/vendor/topthink/framework/src/think/Container.php on line 35
Script @php think service:discover handling the post-autoload-dump event returned with error code 255
解决办法:
找到应该修改的文件:
\vendor\psr\container\srcContainerInterface.php
将$id前的变量类型限制去掉。即可解决上述报错。
public function has(string $id);
问题二:
运行框架,会提示如下错误
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">=*.*.*".
解决办法:
打开框架中的composer.json,修改下面行。然后执行composer dump 命令。问题解决
"config": {
"platform-check": false
},
问题三:
执行 composer update 报错
[Composer\Downloader\TransportException]
The "https://packagist.phpcomposer.com/packages.json" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messa
ges:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Failed to enable crypto
failed to open stream: operation failed
解决办法:
composer config -g repo.packagist composer https://packagist.org
composer self-update