Fix #1291: Remove PHP 8.x deprecated/removed functions#1609
Fix #1291: Remove PHP 8.x deprecated/removed functions#1609mambax7 merged 2 commits intoXOOPS:masterfrom
Conversation
- xoopslocal.php: Remove utf8_encode() and utf8_decode() fallback calls (deprecated in PHP 8.1, removed in PHP 9.0). Both methods now always use mb_convert_encoding(), which is available in all supported PHP versions. Also remove the utf8_encode() fallback from convert_encoding() which was only reached after mb_convert_encoding() and iconv() both failed - an extremely unlikely scenario that now falls through cleanly. - common.php: Remove the get_magic_quotes_gpc() / get_magic_quotes_runtime() BC polyfill block. These functions were removed in PHP 8.0. The polyfill was guarded with function_exists() and no XOOPS code still calls them. The only remaining reference is in htmlpurifier which already guards with function_exists() and a PHP version check. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 WalkthroughRemoved legacy compatibility shims: multibyte gating around UTF-8 encode/decode now always attempts mb_convert_encoding then iconv, and a PHP 8-era polyfill for get_magic_quotes_* was removed from common.php. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@htdocs/class/xoopslocal.php`:
- Around line 59-67: The docblock for utf8_encode declares `@return` string but
currently returns the original $text (mixed) on failure; change the fallback to
return a string by casting the original value (e.g., return (string) $text) so
the function signature is honored, and apply the same change to the utf8_decode
method to ensure both always return string as documented; update only the return
expressions in utf8_encode and utf8_decode to cast the fallback to string.
- Around line 61-66: Rename the snake_case variable $converted_text to camelCase
$convertedText in the encoding conversion block and update all references and
checks accordingly so they match the existing camelCase usage in
convert_encoding(); specifically change the assignment from
mb_convert_encoding(...), the conditional that checks !== false and
!is_array(...), and the return of the converted value to use $convertedText (and
leave the fallback return $text unchanged).
- Around line 78-83: The variable name $converted_text is inconsistent with the
class' camelCase style; rename it to $convertedText (and update all its
occurrences in this method/class) so the mb_convert_encoding result is stored in
$convertedText, the conditional checks and the return use $convertedText, and
keep the fallback return $text unchanged; ensure references to $converted_text
elsewhere in the class/file are updated to $convertedText to maintain
consistency.
There was a problem hiding this comment.
Pull request overview
Removes legacy compatibility shims and deprecated PHP string-encoding helpers from the XOOPS 2.5.x core to avoid PHP 8.x deprecations/removals while keeping encoding conversion behavior centralized in XoopsLocalAbstract.
Changes:
- Removed
get_magic_quotes_gpc()/get_magic_quotes_runtime()BC polyfill from core initialization. - Updated
XoopsLocalAbstract::utf8_encode()/utf8_decode()to rely onmb_convert_encoding()only, and removed theutf8_encode()fallback inconvert_encoding().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| htdocs/include/common.php | Removes magic-quotes polyfill functions from the core bootstrap. |
| htdocs/class/xoopslocal.php | Replaces deprecated utf8_encode/utf8_decode fallbacks with mb_convert_encoding() and simplifies convert_encoding(). |
xoopslocal.php utf8_encode() / utf8_decode() improvements:
- Add function_exists('mb_convert_encoding') guard so the methods
work safely on environments where mbstring is not installed (falls
back to iconv, then a passthrough string cast)
- Add iconv() fallback for environments with iconv but not mbstring
- Use explicit source/target encodings (ISO-8859-1 <-> UTF-8) instead
of 'auto', which matches the historical semantics of the deprecated
PHP utf8_encode()/utf8_decode() functions
- Rename $converted_text to $convertedText (camelCase consistency with
the rest of the class)
- Change fallback return from $text to (string)$text to honour the
@return string contract
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|



Summary
class/xoopslocal.php: Removeutf8_encode()andutf8_decode()fallback calls (deprecated PHP 8.1, removed PHP 9.0). Both methods now always usemb_convert_encoding(). Also removes the unreachableutf8_encode()fallback inconvert_encoding().include/common.php: Remove theget_magic_quotes_gpc()/get_magic_quotes_runtime()BC polyfill block. These functions were removed in PHP 8.0 and no XOOPS code calls them anymore. The only remaining third-party reference (htmlpurifier) already guards withfunction_exists()and a PHP version check.Test plan
utf8_encode/utf8_decodeget_magic_quotes_gpcFixes #1291
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes