fix: address PHP 8.2 deprecation warnings and improve AI API robustness#1131
Merged
zhblue merged 6 commits intozhblue:masterfrom Feb 12, 2026
Merged
fix: address PHP 8.2 deprecation warnings and improve AI API robustness#1131zhblue merged 6 commits intozhblue:masterfrom
zhblue merged 6 commits intozhblue:masterfrom
Conversation
修复内容: 这些错误主要是由于在 PHP 8.1+ 环境下,代码尝试访问不存在的数组键( Undefined array key "error" )以及将 null 传递给字符串函数(如 strpos , strlen , str_replace )导致的。 1. 修复 is_valid() 函数 : - 在 reinfo.php:L20-25 中增加了对输入参数 $str2 的空值检查。如果 $str2 为 null (例如当数据库中没有运行错误记录时),函数将直接返回 false ,从而避免了 strlen() 和 str_split() 报错。 2. 优化 runtimeinfo 数据处理 : - 在 reinfo.php:L81-91 中,引入了 $error_info 变量来安全地获取运行错误信息。 - 使用了空接合操作符 ( ?? "" ) 确保在调用 str_replace 和 htmlentities 时,即使没有错误信息,传递的也是空字符串而不是 null 。 - 在调用 strpos() 之前增加了 $error_info !== null 的判断,彻底解决了 Undefined array key 和 Deprecated 警告。 3. 消除变量冲突 : - 原代码重复使用了 $row 变量,导致 solution 表的数据和 runtimeinfo 表的数据混淆。现在使用了独立的 $row_runtime 变量,使逻辑更加清晰且安全。
- 增加对 $_POST['showInMenu'] 的 isset 检查,解决未勾选复选框时的警告。 - 引入 ob_start() 并将 header 跳转改为 JS alert + location 方式,彻底解决 "headers already sent" 问题。 - 优化代码结构,将数据查询逻辑移至 kindeditor 包含之前。 - 清理 textarea 渲染时的多余空白字符。
- 增加 ob_start() 确保输出缓冲。 - 修复 $_POST['showInMenu'] 的未定义键警告。 - 将保存后的跳转方式改为带提醒的 JS 跳转,提升用户体验并避免跳转失效。
- 在文件顶部增加 ob_start(),确保在包含 admin-header.php 或其他包含文件时不会因意外输出导致 header 相关错误。
- 移除文件开头的空白字符,防止该文件被其他 PHP 脚本 include 时触发提前输出,从而引发 "Cannot modify header information" 错误。
zhblue
reviewed
Feb 12, 2026
Owner
zhblue
left a comment
There was a problem hiding this comment.
textarea>后面要紧跟<?php
否则每次编辑会在头部多出空白字符
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: address PHP 8.2 deprecation warnings and improve AI API robustness
${var}string interpolation with{$var}in common.php to fix PHP 8.2+ compatibility issues.pdo_queryresults in common.php and yuanqi.php to prevent "非法参数" errors when querying non-existent solution IDs or problem IDs.fix: resolve permission errors and undefined variable in problem_add.php