The mbstring.func_overload directive in PHP replaces standard string functions with multibyte-safe versions, ensuring proper handling of non-ASCII characters (like UTF-8, Japanese, Cyrillic, etc.).

Important: This setting is deprecated since PHP 7.2 and removed in PHP 8.0. If you are running PHP 7.2+, you should remove it from your configuration.

What Does mbstring.func_overload Do?

When enabled, PHP replaces standard functions (e.g., strlen(), strpos(), substr()) with their mbstring equivalents (mb_strlen(), mb_strpos(), mb_substr()).

Example Behavior

Standard Function Overloaded Equivalent
strlen() > Returns byte length mb_strlen() > Returns character length
substr() > Cuts bytes mb_substr() > Cuts characters

Helps handle UTF-8 text correctly, avoiding issues where multi-byte characters get cut off incorrectly.

Checking mbstring.func_overload Value

1

Method 1: Use phpinfo()

  1. Create a new PHP file (info.php):
  2. <?php
    phpinfo();
    ?>
  3. Open the file in a browser (http://yourdomain.com/info.php).
  4. Search for "mbstring.func_overload" in the output.
2

Method 2: Check via CLI

Run this command in the terminal:

php -i | grep mbstring.func_overload

If it returns mbstring.func_overload => 0, it is disabled.

Enabling or Disabling mbstring.func_overload

Modify php.ini

Edit your PHP configuration file (php.ini):

sudo nano /etc/php/{version}/cli/php.ini # Ubuntu/Debian
sudo nano /etc/php.ini # CentOS/RHEL

Locate the line:

mbstring.func_overload = 0

Change it to:

mbstring.func_overload = 2

Save and restart Apache or PHP-FPM:

sudo systemctl restart apache2 # Ubuntu/Debian
sudo systemctl restart httpd # CentOS/RHEL

Disable mbstring.func_overload for PHP 7.2+

If you are using PHP 7.2+ or PHP 8, remove this line from php.ini:

mbstring.func_overload = 2

Why?

  • mbstring.func_overload is deprecated in PHP 7.2 and removed in PHP 8.0.
  • Keeping it enabled may cause errors like:
  • Fatal error: Directive 'mbstring.func_overload' is no longer available in Unknown on line 0
  • Instead, manually replace strlen() with mb_strlen(), substr() with mb_substr(), etc.

Alternative: Using Multibyte Functions Directly

If mbstring.func_overload is removed (PHP 8.0+), you should replace standard functions manually:

Before (mbstring.func_overload enabled)

echo strlen("Привет"); // Might return incorrect byte length
echo substr("Привет", 0, 3); // Cuts characters incorrectly

After (Using Multibyte Functions)

echo mb_strlen("Привет", "UTF-8"); // Correct character length
echo mb_substr("Привет", 0, 3, "UTF-8"); // Correct substring handling

Common Issues & Fixes

Issue Solution
Deprecated warning in PHP 7.2+ Remove mbstring.func_overload from php.ini.
String functions behaving strangely Ensure correct use of mb_* functions.
Still getting errors after removal? Restart Apache or PHP-FPM.
Encoding issues in scripts? Set mb_internal_encoding("UTF-8"); in scripts.
  • mbstring.func_overload was useful for handling multibyte characters but is deprecated in PHP 7.2+ and removed in PHP 8.0+.
  • If using PHP 7.2 or later, remove it and manually replace string functions with mb_* equivalents.
  • If using older PHP versions, enable it in php.ini but be prepared to migrate your code.