Issue

When you run your script in PHP 7.4 or higher on Windows, you get an error message indicating that the function "mb_ereg()",  "mb_eregi()", "mb_ereg_match()", "mb_ereg_replace()", "mb_eregi_replace()", "mb_ereg_replace_callback()", "mb_regex_encoding()", and/or "mb_regex_set_options()" is not defined.

Environment

Running Zend Server version 2021 or higher, or ZendPHP, on any compatible version of Windows, using PHP 7.4 or higher.

Details

Starting in PHP 7.4, the PHP project stopped shipping the oniguruma library with PHP, in favor of using the versions shipped with the underlying operating system. The oniguruma library provides functionality on which the mbstring extension relies.

On Windows, Microsoft recommends using libmbfl as a replacement for oniguruma, and started compiling the mbstring extension against it starting with PHP 7.4.  Zend followed suit with the release of PHP 7.4 binaries in Zend Server 2021, and with its ZendPHP builds for Windows.

Unfortunately, libmbfl does not provide regular expression matching or replacement features, and, as such, the functions listed in the issue description are not defined.

Recommendations

If you are using these functions directly in your own code, we recommend using preg_match() or preg_replace() instead, using the "u" PCRE flag when matching: e.g., "/^\w/u". The "u" flag enables matching against unicode character sets, and using it with PCRE will actually expand your matching capabilities.

If you are using a third party library that uses one of these functions, Zend by Perforce provides a polyfill library that you can install via Composer (https://getcomposer.org):

composer require zendtech/polyfill-mb-ereg

Once installed, the Composer autoloader will load the replacement functions, making them transparently available to other libraries.

  • No labels