You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP8兼容性问题求助:Unsupported operand types: array & int错误

Fix for PHP8 Unsupported operand types Error

The error occurs because fetch_permissions() now returns an associative array of permissions instead of an integer bitmask. PHP8 strictly prohibits bitwise operations (&) between an array and integer—an operation that silently failed or coerced in older PHP versions.

Corrected Code

Replace the two problematic lines in your process_attachments() function with direct array key checks:

$attach->process_attachments(
    $this->post,
    $this->post['allattachments'],
    (THIS_SCRIPT == 'external'),
    can_moderate($this->forum['forumid'], 'canmoderateattachments'),
    $forumperms['cangetattachment'], // Replaced bitwise operation with array lookup
    $forumperms['canseethumbnails']  // Replaced bitwise operation with array lookup
);

Explanation

Modern forum software (like vBulletin) shifted from integer bitmasks to explicit permission arrays. Instead of using bitwise logic to extract permissions from a single integer, you now access the permission directly via its key in the $forumperms array.

For added safety (in case a permission key is missing), use the null coalescing operator to fall back to false:

$forumperms['cangetattachment'] ?? false,
$forumperms['canseethumbnails'] ?? false

内容的提问来源于stack exchange,提问作者ZADeltaEcho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 14:30:49