Symfony Polyfill Mbstring fails with an undefined iconv_strlen() function
Call to undefined function Symfony\Polyfill\Mbstring\iconv_strlen()Short answer
The mbstring polyfill, used when the mbstring extension is missing, calls iconv_strlen() inside its own code. If the server has neither the iconv extension nor symfony/polyfill-iconv, that call fails. Install the mbstring extension for the PHP your web server runs, or enable iconv or add symfony/polyfill-iconv.
Fix it fast
1Find out which cause you have
List the extensions loaded by the PHP that serves the site. Run it with the same PHP binary or php-fpm version as the site; the command-line PHP can differ from the web one.
php -m | grep -iE "mbstring|iconv" php -v2Match what you see, then jump to its fix
What does the error look like?
Call to undefined function Symfony\Polyfill\Mbstring\iconv_strlen()Fatal error: Uncaught Error in vendor/symfony/polyfill-mbstring/Mbstring.php
Cause 1 of 2
The mbstring extension is not installed, so the polyfill runs
1Check
A polyfill is used only when the native function is missing. The polyfill only fills in when the extension is absent, and the iconv_strlen() call comes from inside it.
php -m | grep -i mbstring
composer show symfony/polyfill-mbstring2Fix
Install the mbstring extension for your PHP version and restart PHP. On Debian or Ubuntu the package is php-mbstring; with a version in the name, such as php8.3-mbstring, use the version you run.
sudo apt install php-mbstring
sudo systemctl restart php8.3-fpm3Verify
mbstring appears in the module list, then reload the page that failed.
php -m | grep -i mbstringConfirmed by php.net
Cause 2 of 2
Neither the iconv extension nor symfony/polyfill-iconv is available
1Check
The mbstring polyfill calls iconv_strlen() in mb_strlen(), mb_substr() and mb_strwidth(), and the polyfill file does not define that function itself. PHP has the iconv extension on unless it was built with --without-iconv, so a missing one points to a minimal or custom build.
php -m | grep -i iconv
composer show symfony/polyfill-iconv2Fix
Install the iconv extension for your PHP build, or add the iconv polyfill, which implements the iconv functions in plain PHP.
composer require symfony/polyfill-iconv3Verify
Check that the function now exists, from the same PHP the site uses.
php -r 'var_dump(function_exists("iconv_strlen"));'Confirmed by github.com
How do I stop it coming back?
- Install mbstring and iconv in the base image or server setup instead of leaving them to polyfills.
- Run php -m on the server after each PHP upgrade and compare it with the extensions in composer.json.
- Check the extension list for php-fpm and for the CLI separately, since they can use different ini files.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
CodeIgniter 4 cannot write its cache files
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/
CodeIgniter 4's file cache needs a cache directory that the web server can really write to.
2 causes, each with a fixBack end
CodeIgniter 3 loads the model but the property is undefined
The model name you are loading is the name of a resource that is already being used: user
CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.
2 causes, each with a fixBack end
CodeIgniter 3 stops with "Your system folder path does not appear to be set correctly"
503 Service Unavailable
CodeIgniter 3's front controller resolves $system_path and then checks that the result is a directory.
3 causes, each with a fix