tp5项目在本地运行没有问题,在linux上报错

其实不是linux的问题 ,最后发现是本地和线上linux部署的环境不同才导致这种问题 

tp5在php版本8.1以上会出现好多不兼容的问题 ,最好的解决办法就是给php进行降级操作


During inheritance of Iterator: Uncaught think\exception\ErrorException: Return type of PhpOffice\PhpSpreadsheet\Worksheet\Iterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in E:\phpstudy_pro\WWW\Enterprise_data\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Worksheet\Iterator.php:69
Stack trace:
#0 E:\phpstudy_pro\WWW\Enterprise_data\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Worksheet\Iterator.php(7): think\Error::appError(8192, 'Return type of ...', 'E:\\phpstudy_pro...', 69)
#1 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\Loader.php(544): include('E:\\phpstudy_pro...')
#2 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\Loader.php(58): think\__include_file('E:\\phpstudy_pro...')
#3 E:\phpstudy_pro\WWW\Enterprise_data\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Spreadsheet.php(1099): think\Loader::autoload('PhpOffice\\PhpSp...')
#4 E:\phpstudy_pro\WWW\Enterprise_data\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\ReferenceHelper.php(937): PhpOffice\PhpSpreadsheet\Spreadsheet->getWorksheetIterator()
#5 E:\phpstudy_pro\WWW\Enterprise_data\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Worksheet\Worksheet.php(892): PhpOffice\PhpSpreadsheet\ReferenceHelper->updateNamedFormulas(Object(PhpOffice\PhpSpreadsheet\Spreadsheet), 'Worksheet', '\xE4\xB8\xB9\xE9\x98\xB3\xE5\xB8\x82\xE5\xAE\x8F\xE8\xA7\x82...')
#6 E:\phpstudy_pro\WWW\Enterprise_data\application\admin\controller\Admin.php(658): PhpOffice\PhpSpreadsheet\Worksheet\Worksheet->setTitle('\xE4\xB8\xB9\xE9\x98\xB3\xE5\xB8\x82\xE5\xAE\x8F\xE8\xA7\x82...')
#7 [internal function]: app\admin\controller\Admin->downloadTemplate()
#8 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\App.php(226): ReflectionMethod->invokeArgs(Object(app\admin\controller\Admin), Array)
#9 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\App.php(364): think\App::invokeMethod(Array)
#10 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\App.php(134): think\App::module(Array, Array, true)
#11 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\start.php(18): think\App::run()
#12 E:\phpstudy_pro\WWW\Enterprise_data\public\index.php(18): require('E:\\phpstudy_pro...')
#13 {main}

或者下面这种报错


During inheritance of JsonSerializable: Uncaught think\exception\ErrorException: Return type of think\Model::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\Model.php:1438
Stack trace:
#0 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\Model.php(40): think\Error::appError(8192, 'Return type of ...', 'E:\\phpstudy_pro...', 1438)
#1 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\Loader.php(544): include('E:\\phpstudy_pro...')
#2 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\Loader.php(58): think\__include_file('E:\\phpstudy_pro...')
#3 E:\phpstudy_pro\WWW\Enterprise_data\application\admin\model\Admin.php(7): think\Loader::autoload('think\\Model')
#4 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\Loader.php(544): include('E:\\phpstudy_pro...')
#5 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\Loader.php(58): think\__include_file('E:\\phpstudy_pro...')
#6 E:\phpstudy_pro\WWW\Enterprise_data\application\admin\controller\Admin.php(84): think\Loader::autoload('app\\admin\\model...')
#7 [internal function]: app\admin\controller\Admin->getCompanyXin()
#8 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\App.php(226): ReflectionMethod->invokeArgs(Object(app\admin\controller\Admin), Array)
#9 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\App.php(364): think\App::invokeMethod(Array)
#10 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\library\think\App.php(134): think\App::module(Array, Array, true)
#11 E:\phpstudy_pro\WWW\Enterprise_data\thinkphp\start.php(18): think\App::run()
#12 E:\phpstudy_pro\WWW\Enterprise_data\public\index.php(18): require('E:\\phpstudy_pro...')
#13 {main}

解决办法:

可以通过进行php降级操作,我用的是xampp所以直接卸载当前高版本的,在安装一个php8.1之下的就行

先卸载当前xampp 

cd /opt/lampp

./uninstall

等待完成卸载 在重新安装即可

可参考这个链接:linux配置xampp(可内网安装)_荒-漠的博客-CSDN博客linux服务器搭建php项目,包括环境配置和必备软件 持续更新https://blog.csdn.net/qq5201314wx/article/details/121406038?spm=1001.2014.3001.5501

Logo

更多推荐