找回密码
 新建账号

Discuz X 3.5 PHP 8 Unsupported operand types: string - string

[复制链接]
php 发表于 2022/12/27 16:35 | 显示全部楼层 |阅读模式
Discuz! System Error
Unsupported operand types: string - string
PHP Debug
No.FileLineCode
1forum.php71require(%s)
2source/module/forum/forum_viewthread.php1006getuploadconfig(%d, %d)
3source/function/function_upload.php89break()

www.51-n.com 已经将此出错信息详细记录, 由此给您带来的访问不便我们深感歉意

在 PHP 8.0 以上版本中,对非数值值进行数学运算会触发致命错误 Fatal error: Uncaught TypeError: Unsupported operand types: string - string,只要参与运算的值有一个以上不是数值就会触发致命错误,数学运算包括但不限于 + - * / ** 等各种数学计算,非数值类型包括但不限于字符串,数组,对象,但也有特例,本文发布时 PHP 8.2 刚发行不久,在 PHP 8.0 - 8.2 中 null, true, false 等非数值值仍然可以参于数学运算,不会触发错误。

具体到 Discuz X 3.5 来说,Discuz! 报错从最后一个倒过来排查,在 source/function/function_upload.php 的第 89 行,
  1. $config['maxattachnum'] = $_G['group']['maxattachnum'] - $todayattachs;
复制代码
$todayattachs 是一个字符串,不是数值,导致了这个 Unsupported operand types: string - string 的致命错误,同理还有第 95 行
  1. $config['maxsizeperday'] = $_G['group']['maxsizeperday'] - $todayattachsize;
复制代码
$todayattachsize 是一个字符串,不是数值,也会导致 Unsupported operand types: string - string 的致命错误。
解决办法就是将以上两行分别改成下面两行。
  1. $config['maxattachnum'] = (float)$_G['group']['maxattachnum'] - (float)$todayattachs;
复制代码
  1. $config['maxsizeperday'] = (float)$_G['group']['maxsizeperday'] - (float)$todayattachsize;
复制代码
类似的错误还有 source/class/class_credit.php 第 228 行 报错 Unsupported operand types: int + string
  1. $creditarr['extcredits'.$i] += $_G['setting']['creditspolicymobile'];
复制代码
应该修改为
  1. $creditarr['extcredits'.$i] += (int)$_G['setting']['creditspolicymobile'];
复制代码

手机版|轻松E站

GMT+8, 2024/4/19 08:26

快速回复 返回顶部 返回列表