Mbstring polyfill calls undefined iconv
kontur opened this issue · comments
Hey,
I'm authoring a Wordpress plugin and use Twig in it. I've recently updated my Twig library I use in it and this recently installed this polyfill package (polyfill-mbstring v1.22.1). I got the following report / error log from a user using PHP 7.3.27:
An error of type E_ERROR was caused in line 285 of the file /home/---/public_html/wp-content/plugins/fontsampler/vendor/symfony/polyfill-mbstring/Mbstring.php. Error message: Uncaught Error: Call to undefined function Symfony\Polyfill\Mbstring\iconv() in /home/---/public_html/wp-content/plugins/fontsampler/vendor/symfony/polyfill-mbstring/Mbstring.php:285
Stack trace:
#0 /home/---/public_html/wp-content/plugins/fontsampler/vendor/symfony/polyfill-mbstring/Mbstring.php(585): Symfony\Polyfill\Mbstring\Mbstring::mb_convert_case('lerySlideshowTh...', 1, 'ASCII')
#1 /home/---/public_html/wp-content/plugins/fontsampler/vendor/symfony/polyfill-mbstring/bootstrap.php(67): Symfony\Polyfill\Mbstring\Mbstring::mb_strtolower('lerySlideshowTh...', 'ASCII')
#2 /home/---/public_html/wp-content/plugins/redux-framework/redux-core/inc/classes/class-redux-autoloader.php(59): mb_strtolower('lerySlideshowTh...', 'ASCII')
#3 [internal function]: Redux_Autoloader->load('lerySlideshowTh...')
#4 [internal function]: spl_autoload_call('JSJGallerySlide...')
#5 /home/---/public_html/wp-content/plugins/jsj-gallery-slideshow/themes/default/theme-main.php(12): class_exists('JSJGallerySlide..
Looking at L285 the code seems like a simple call to iconv
which should be available in that PHP version. Yet the error log above reads like it is trying to call iconv as method of Mbstring — or am I misinterpreting this?
Note that a error of this gravity will actually shut down that users entire Wordpress site, caused by my plugin — so quite a nasty surprise just from having updated Twig.
Any idea what's going on here?
I suppose ext-iconv is not installed on this setup. Try installing the iconv polyfill next to the mbstring one.
Alternatively, try installing ext-iconv.
Cheers, will run a fix with this past the user who reported and see if that resolves the issue. Should the polyfill, per definition, not detect that iconv might be needed? Or rather, should not the mbstring polyfill require the iconv polyfill to cover this case?
The iconv polyfill is a heavy one, we don't want to push MB of maps to users, when in practice, iconv is installed on 99.9% of the servers.
Ppl should really install ext-iconv, that's the proper fix.
@nicolas-grekas should we fully-qualify the iconv
calls to have better error messages in such case (saying iconv
does not exist rather than Symfony\Polyfill\Mbstring\iconv
?
Sorry folks, no bandwidth or deeper insight into this library to put a PR together, just reporting the issue I hit (via a user reporting it in a Wordpress environment).
@kontur I did the PR.