The mbstring.func_overload directive ensures that Bitrix CMS (or Bitrix24) handles multibyte strings correctly, particularly for non-ASCII characters such as Cyrillic. This directive replaces standard PHP string functions like strlen(), substr(), and strpos() with their multibyte-safe equivalents (mb_strlen(), mb_substr(), mb_strpos()).

However, since mbstring.func_overload has been deprecated in PHP 7.2 and removed in PHP 8.0, you need to handle it carefully, depending on your PHP version and Bitrix configuration.

Steps to Set mbstring.func_overload for Bitrix

Enable mbstring.func_overload in php.ini

1

Locate the php.ini File

The php.ini file is typically located in:

  • /etc/php/{version}/apache2/php.ini for Apache.
  • /etc/php/{version}/cli/php.ini for command-line PHP.
  • /etc/php/{version}/fpm/php.ini for Nginx with PHP-FPM.
2

Edit the File

Open the file using a text editor:

sudo nano /etc/php/{version}/apache2/php.ini
3

Find or Add mbstring.func_overload

Add or modify the directive:

mbstring.func_overload = 2
4

Restart the Web Server

For Apache:

sudo systemctl restart apache2

For Nginx (PHP-FPM):

sudo systemctl restart php-fpm

Verify the Setting

To ensure mbstring.func_overload is enabled:

  • Using phpinfo():
    1. Create a PHP file (e.g., info.php) with the following content:
    2. <?php
      phpinfo();
      ?>
    3. Open it in a browser (http://yourdomain.com/info.php) and search for mbstring.func_overload.
  • Using Command Line: Run the following command:
  • php -i | grep mbstring.func_overload

    Output should show:

    mbstring.func_overload => 2 => 2

Adjust Bitrix Environment

If mbstring.func_overload is required by your version of Bitrix:

  • Ensure that all other mbstring settings in php.ini are correctly configured:
mbstring.language = Neutral
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.http_output = UTF-8

Handling mbstring.func_overload in PHP 7.2+

1

Check PHP Version

  • If you are using PHP 7.2 or later, the mbstring.func_overload directive is deprecated.
  • If you are using PHP 8.0 or later, it is removed and should not be used.
2

Remove the Directive

If your PHP version does not support mbstring.func_overload, remove it from php.ini:

sudo nano /etc/php/{version}/apache2/php.ini

Comment out or delete the line:

; mbstring.func_overload = 2
3

Update Bitrix Code

  • Replace calls to standard string functions (strlen(), substr()) with multibyte-safe functions (mb_strlen(), mb_substr()) directly in the codebase if necessary.
  • Alternatively, contact Bitrix Support for a version of Bitrix compatible with modern PHP versions.

Testing for Bitrix Compatibility

  1. Run Bitrix Environment Check Script: Download and run the Bitrix environment check script to verify all server settings:
  2. http://yourdomain.com/bitrixsetup.php
  3. Fix Any Detected Warnings: The script will flag any misconfigurations, including issues related to mbstring.func_overload.

Best Practices for Modern PHP Versions

If mbstring.func_overload is unavailable or not recommended for your PHP version:

  1. Set Internal Encoding Manually: Add this to your Bitrix init.php file:
  2. mb_internal_encoding("UTF-8");
  3. Use mb_* Functions in Custom Scripts: Replace any standard string functions with multibyte-safe versions:
    • strlen() > mb_strlen()
    • strpos() > mb_strpos()
    • substr() > mb_substr()
  4. Upgrade to a Bitrix Version Compatible with PHP 7.2+ or 8.0: Older versions of Bitrix may rely on deprecated functionality. Upgrading ensures compatibility with modern environments.

Troubleshooting Common Issues

Problem Solution
Bitrix requires mbstring.func_overload Enable it in php.ini if using PHP < 7.2.
Error: "mbstring.func_overload is removed in PHP 8" Remove the directive and update Bitrix or use mb_* functions.
Cyrillic characters not displayed correctly Ensure mb_internal_encoding("UTF-8") is set and files are saved in UTF-8 encoding.
PHP logs show errors after removal Debug Bitrix codebase for unsupported functions like strlen() and replace with mb_strlen().
  • If you are using PHP 7.1 or earlier, enable mbstring.func_overload = 2 for Bitrix to ensure proper multibyte string handling.
  • For PHP 7.2+, avoid using mbstring.func_overload and update your Bitrix installation or use mb_* functions in your scripts.
  • Always test your server environment with the Bitrix environment check script.