Skip to content

Fix #1291: Remove PHP 8.x deprecated/removed functions#1609

Merged
mambax7 merged 2 commits intoXOOPS:masterfrom
mambax7:fix/1291-deprecated-code-php8x
Feb 20, 2026
Merged

Fix #1291: Remove PHP 8.x deprecated/removed functions#1609
mambax7 merged 2 commits intoXOOPS:masterfrom
mambax7:fix/1291-deprecated-code-php8x

Conversation

@mambax7
Copy link
Collaborator

@mambax7 mambax7 commented Feb 17, 2026

Summary

  • class/xoopslocal.php: Remove utf8_encode() and utf8_decode() fallback calls (deprecated PHP 8.1, removed PHP 9.0). Both methods now always use mb_convert_encoding(). Also removes the unreachable utf8_encode() fallback in convert_encoding().
  • include/common.php: Remove the get_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 with function_exists() and a PHP version check.

Test plan

  • Run on PHP 8.1+ — no deprecation warnings for utf8_encode/utf8_decode
  • Confirm encoding conversion still works for multibyte content
  • Confirm no errors from missing get_magic_quotes_gpc

Fixes #1291

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Refactor
    • Streamlined character encoding conversion to improve reliability of text handling and reduce unexpected encoding issues for users.
    • Removed legacy PHP compatibility fallbacks, modernizing the codebase and reducing maintenance overhead while aligning with current PHP behavior.

- 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>
Copilot AI review requested due to automatic review settings February 17, 2026 02:10
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

Removed 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

Cohort / File(s) Summary
Multibyte encoding logic
htdocs/class/xoopslocal.php
Removed XOOPS_USE_MULTIBYTES gating in utf8_encode() and utf8_decode(); functions now attempt mb_convert_encoding() when available, fall back to iconv() with transliteration, and otherwise return the original string. convert_encoding() no longer force-falls back to utf8_encode() when target is utf-8.
PHP 8 magic quotes polyfill removal
htdocs/include/common.php
Deleted the PHP 8 compatibility polyfill block that defined get_magic_quotes_gpc() and get_magic_quotes_runtime() when absent. No other public signatures changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix #1291: Remove PHP 8.x deprecated/removed functions' directly and clearly describes the main change: removing deprecated PHP functions to fix issue #1291.
Linked Issues check ✅ Passed The pull request addresses the primary objective of #1291 by removing deprecated PHP functions (utf8_encode, utf8_decode, get_magic_quotes_gpc/runtime) that have been marked for cleanup.
Out of Scope Changes check ✅ Passed All changes are directly related to removing deprecated/removed PHP functions from xoopslocal.php and common.php as specified in issue #1291; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 on mb_convert_encoding() only, and removed the utf8_encode() fallback in convert_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>
@sonarqubecloud
Copy link

@mambax7 mambax7 merged commit 6a85a28 into XOOPS:master Feb 20, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecated code cleanup

2 participants