Fix #1215: Replace removed money_format() with NumberFormatter#1607
Fix #1215: Replace removed money_format() with NumberFormatter#1607mambax7 wants to merge 2 commits intoXOOPS:masterfrom
Conversation
money_format() was removed in PHP 8.0. Replace the English locale implementation with NumberFormatter::formatCurrency() from the intl extension, which is the standard PHP approach for locale-aware currency formatting. The $format parameter is kept for backward compatibility but ignored, as NumberFormatter handles locale-specific formatting internally. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
WalkthroughReplaced the deprecated PHP Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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/language/english/locale.php`:
- Line 72: Import the NumberFormatter class and remove the inline FQN: add a
top-level use NumberFormatter; statement (after the opening PHP tag / namespace)
and change the instantiation that currently uses \NumberFormatter (the $fmt =
new \NumberFormatter(...) call) to use the short class name (new
NumberFormatter(...)) so the file follows PSR-12 and resolves the PHPMD
MissingImport hint.
- Around line 66-68: Update the docblock for the function in locale.php that
declares the unused parameter $format so IDEs and PHPMD stop flagging it: mark
the parameter as deprecated in the `@param` line (e.g. "@param string $format
Deprecated - kept for BC") or add an `@internal` note, and additionally add a
PHPMD suppression annotation (e.g.
"@SuppressWarnings(PHPMD.UnusedFormalParameter)") or an equivalent
PhpStorm/PSalm suppression in the docblock; ensure you reference the same
$format parameter name so tools pick up the intent.
- Around line 72-74: The call to NumberFormatter::formatCurrency in locale.php
can return false on failure, so update the code around
$fmt->formatCurrency((float)$number, 'USD') to check the result and ensure a
string is returned; if formatCurrency returns false, either log/raise an error
(e.g., throw an exception) or return a safe fallback string (like a plain
numeric formatting with a USD suffix), and propagate that change from the
function so its return type remains string—locate the $fmt variable and the
formatCurrency call to implement the check and fallback handling.
There was a problem hiding this comment.
Pull request overview
Updates the English locale implementation to avoid PHP 8+ incompatibility from the removed money_format() function by switching to intl’s NumberFormatter.
Changes:
- Replace
money_format()usage withNumberFormatter::formatCurrency()in the English locale. - Remove the per-call
setlocale(LC_MONETARY, ...)usage and update the method PHPDoc to reflect the new behavior.
- Add extension_loaded('intl') guard with number_format() fallback for
environments where the intl extension is not installed
- Cache NumberFormatter in a static variable to avoid repeated ICU
initialization on every call
- Handle formatCurrency() returning false with the same fallback
- Clarify $format docblock: 'legacy money_format()-style format string'
- Add @SuppressWarnings(PHPMD.UnusedFormalParameter) for $format
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@htdocs/language/english/locale.php`:
- Around line 74-86: The static analyzer flags the inline FQN "\NumberFormatter"
as a MissingImport; to fix, add a top-level "use NumberFormatter;" import and
update usage in the function (the static $fmt initialization and any other
references to \NumberFormatter) to use the imported class name "NumberFormatter"
instead of the leading-backslash FQN so the code follows PSR-12 import
conventions.



Summary
money_format()PHP function (removed in PHP 8.0) withNumberFormatter::formatCurrency()from theintlextension in the English locale class$formatparameter is retained for backward compatibility but is no longer used, asNumberFormatterhandles locale-specific formatting internallysetlocale(LC_MONETARY)call removed as it is not needed byNumberFormatterTest plan
XoopsLocal::money_format()Fixes #1215
🤖 Generated with Claude Code
Summary by CodeRabbit