继续阅读完整内容
支持我们的网站,请点击查看下方广告
启用模块报错:Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /var/www/html/templates/ja_allure/html/modules.php on line 37 Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/templates/ja_allure/html/modules.php on line 43
旧 模板 ja_allure,它包含的 modules.php 文件中有一些代码写法不符合PHP新版本的严格标准。
解决方案:修复模板文件
用代码编辑器打开 /templates/ja_allure/html/modules.php,找到第37行和第43行附近。
- 第37行附近,找到 preg_match(...) 调用,确保它的第二个参数($subject)是一个字符串,而不是 null。通常在它前面加一个空字符串检查。
- 第43行附近,找到 htmlspecialchars(...) 调用,确保它的第一个参数不是 null。
一个简单的修复方法是在使用变量前,用 ??(空值合并运算符)或 isset() 确保它不是 null。例如,可能将原来的:
echo htmlspecialchars($tag);
改为:
echo htmlspecialchars($tag ?? '');
具体代码:
37行:
$badge = preg_match ('/badge/', $params->get('moduleclass_sfx'))? '<span class="badge"> </span>' : '';
改为:
// 获取 moduleclass_sfx,如果为 null 则使用空字符串$moduleClassSfxParam = $params->get('moduleclass_sfx', '');// 确保参数是字符串类型$badge = preg_match('/badge/', (string)$moduleClassSfxParam) ? '<span class="badge"> </span>' : ''; (此改动无效)
或改为更简洁的写法(这个有效):
$badge = preg_match('/badge/', (string)$params->get('moduleclass_sfx', '')) ? '<span class="badge"> </span>' : '';
43行:
$moduleClassSfx = htmlspecialchars($params->get('moduleclass_sfx'));
// 使用空字符串作为默认值,并指定编码$moduleClassSfx = htmlspecialchars($params->get('moduleclass_sfx', ''), ENT_COMPAT, 'UTF-8');