Skip to content

[4.x] Fall back to mbstring in StringHelper::transcode() without ext-iconv - #78

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-transcode-without-iconv
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-transcode-without-iconv

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

StringHelper::transcode() reads the ICONV_IMPL constant and calls iconv(), but composer.json declares no dependency on ext-iconv, not even in suggest. On a PHP build without iconv, every call throws Error: Undefined constant "ICONV_IMPL". strcmp() and strcasecmp() call transcode() for non-UTF-8 locales, so they fail the same way.

transcode() now falls back to mb_convert_encoding() when ICONV_IMPL is not defined. symfony/polyfill-mbstring is already required. The fallback cannot transliterate: characters that the target encoding cannot represent become ? instead of an approximation (€ → EUR). ext-iconv is added to suggest for that reason. With iconv installed, nothing changes.

Testing Instructions

The existing testTranscode still passes with iconv. The fallback cannot be exercised in the test suite, because iconv is compiled into the PHP builds used here and in CI. It was checked by hand instead:

  • An unqualified undefined constant in the Joomla\String namespace throws Error: Undefined constant. That is what happens to ICONV_IMPL without the extension.
  • In a copy of the class with the guard forced to the fallback, transcode('Åbc Öde €100', 'UTF-8', 'ISO-8859-1') returns "\xC5bc \xD6de ?100".

vendor/bin/phpunit is green, phpcs is clean, and PHPStan reports no errors locally. The PHPStan job in CI fails on 4.x-dev as well (mb_trim and the other PHP 8.4 polyfill functions are not found), and #66 fixes that.

Documentation Changes Required

docs/overview.md (still "TODO" on 4.x-dev) gets a StringHelper::transcode() section that explains the iconv transliteration and the mbstring fallback.

The owner's docs PR #72 says under "Notes on individual methods" that transcode() needs ext-iconv, which is not declared, and raises Error: Undefined constant "ICONV_IMPL" without it. Whichever of the two is merged second must replace that paragraph. #73, #75 and #77 also append sections to the docs/overview.md stub, so expect small conflicts there. #77 also adds an entry to suggest in composer.json, on a different line, and a trial merge of the two branches combines that cleanly.

🤖 Generated with Claude Code

transcode() reads the ICONV_IMPL constant and calls iconv(), but
composer.json declares no dependency on ext-iconv. Without the
extension it threw "Undefined constant ICONV_IMPL". strcmp() and
strcasecmp() call transcode() for non-UTF-8 locales.

Use mb_convert_encoding() when iconv is not available, and suggest
ext-iconv for transliteration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant