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

Testlink‘我的设置’页面无法打开,获取API密钥遇致命错误

环境信息

  • Testlink版本:1.9.20
  • 服务器:Apache24
  • PHP版本:8.3.7

错误详情

Fatal error: Uncaught TypeError: sizeof(): Argument #1 ($value) must be of type Countable|array, null given in C:\Apache24\htdocs\testlink-code-testlink_1_9_20_fixed\lib\functions\object.class.php:600
Stack trace:
#0 C:\Apache24\htdocs\testlink-code-testlink_1_9_20_fixed\lib\functions\object.class.php(576): tlDBObject::createObjectsFromDB(Object(database), NULL, 'tlEvent', true, 4294967295)
#1 C:\Apache24\htdocs\testlink-code-testlink_1_9_20_fixed\lib\functions\logger.class.php(679): tlDBObject::createObjectsFromDBbySQL(Object(database), 'SELECT E.id FRO...', 'id', 'tlEvent', true, 4294967295, 10)
#2 C:\Apache24\htdocs\testlink-code-testlink_1_9_20_fixed\lib\functions\logger.class.php(123): tlEventManager->getEventsFor('16', '1', 'users', '('LOGIN_FAILED'...', 10, NULL, NULL, NULL)
#3 C:\Apache24\htdocs\testlink-code-testlink_1_9_20_fixed\lib\usermanagement\userInfo.php(70): tlLogger->getAuditEventsFor('1', 'users', 'LOGIN_FAILED', 10)
#4 {main} thrown in C:\Apache24\htdocs\testlink-code-testlink_1_9_20_fixed\lib\functions\object.class.php on line 600

解决方案

这个错误源于PHP 8.0+对sizeof()参数的严格类型校验,Testlink 1.9.20的老旧代码未适配该规则——当数据库查询无结果返回null时,直接传入sizeof()触发类型错误。

代码修改步骤

  1. 打开文件 C:\Apache24\htdocs\testlink-code-testlink_1_9_20_fixed\lib\functions\object.class.php
  2. 定位到第600行,找到调用sizeof($rows)的代码,替换为以下两种写法之一:
    • 简洁写法(PHP 7.0+支持):
      sizeof($rows ?? [])
      
    • 兼容写法(PHP 7.3+支持):
      is_countable($rows) ? sizeof($rows) : 0
      

修改原理

  • $rows ?? [] 会在$rows为null时返回空数组,保证sizeof()的参数始终是可数类型。
  • is_countable()专门用于判断变量是否可被计数,从逻辑上避免类型不匹配的问题。

长期建议

Testlink 1.9.20已停止官方维护,后续可能还会出现更多PHP版本兼容问题,建议升级到Testlink最新稳定版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 07:12:12