"Call to undefined function" means the code called a function name that PHP does not know at that moment. The function is not built in, not loaded from an extension, and not defined by any file that has been included so far. In PHP 7 and later it is thrown as an Error, so it appears as Uncaught Error; in PHP 5 it was a plain fatal error.
PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /var/www/html/index.php:12
Stack trace:
#0 {main}
thrown in /var/www/html/index.php on line 12
The function name in the message is your main clue. Which of the groups below it belongs to decides the fix.
Group 1: a PHP extension is not installed or not enabled
Many everyday functions live in extensions that are optional. Typical pairs:
mb_strlen,mb_substr: mbstringcurl_init: curlimagecreatefromjpeg,imagecreatetruecolor: gdsimplexml_load_string: SimpleXML,domforDOMDocumentmysqli_connect: mysqli;pg_connect: pgsqliconv,bcadd,gmp_add,ctype_digit,json_encode(rare now): iconv, bcmath, gmp, ctype, jsonidn_to_ascii,numfmt_create: intl
List what the web PHP actually has loaded:
php -m | sort
php -m | grep -i mbstring
Install the missing one. On Debian or Ubuntu the package name carries your PHP version, and you must restart the right service:
sudo apt install php8.2-mbstring php8.2-curl php8.2-gd php8.2-xml
sudo systemctl restart php8.2-fpm # or: sudo systemctl restart apache2
On RHEL-style systems the names look like php-mbstring, and on shared hosting you enable extensions in the control panel's PHP selector.
Group 2: the function was removed in a newer PHP
Upgrading PHP breaks old code that used functions that no longer exist. Examples documented in the PHP migration guides:
- PHP 7.0: the entire
mysql_*extension (mysql_connect,mysql_query) andereg*functions were removed. - PHP 8.0:
create_function(),each()andmoney_format()were removed.
The error will name the removed function. Replace it (mysqli/PDO for mysql_*, anonymous functions for create_function, foreach for each), or update the plugin, theme or library that uses it. Check composer.json and your CMS's plugin list for versions that declare support for your PHP.
Group 3: your own function is not defined yet
If the missing name is one you wrote, check:
- The file is never included. Add the
requireor confirm the autoloader loads it. Note that Composer autoloads classes, not loose functions, unless the package lists the file underautoload.files. - It is defined conditionally inside an
ifor another function, and the condition did not run. - Namespace mismatch. Inside
namespace App;, a call tohelper()looks forApp\helperfirst and falls back to the global function. If the function lives in another namespace, import it:use function Other\Space\helper;. - A typo or case change in a method-like name. Function names are case-insensitive in PHP, but typos are not.
- A stale deploy: the new file with the function never reached the server, or OPcache serves the old version. Reload PHP-FPM or call
opcache_reset().
Group 4: wrong PHP version for this site
A host that runs different PHP versions per site or per directory can serve your pages with an older build than you tested on. Check the version in use from the page, and compare the extensions of that exact build. In a container, make sure the image you run is the one you built.
Decision order
- Read the function name. Does it start with
mb_,curl_,image,mysqli_,xml? Install the extension first. - Does it look old (
mysql_,ereg,each,create_function)? Fix code or update the package. - Is it your function? Check includes, namespaces and deploy state.
- Still stuck? Confirm the web and CLI PHP are the same version.
Next steps
- Check the page after your fix with the HTTP Status Checker.
- Review Fix 500 Internal Server Error for the wider picture of PHP crashes.
- See PHP class not found for the sibling error with classes.
- Read WordPress plugin conflict troubleshooting if a plugin triggered it.
- Watch the site with an uptime monitor after a PHP upgrade.
FAQ
Why does the CLI work but the website fails?
They are usually different PHP installations with different ini files and extensions. Enable the extension for the PHP-FPM or Apache build that serves the site.
I installed the extension but nothing changed. Why?
The PHP process was not restarted, or you installed it for a different PHP version. Restart PHP-FPM or Apache and verify with phpinfo().
Can I fix this by adding a polyfill?
Sometimes. Packages like symfony/polyfill-mbstring provide pure-PHP fallbacks for some extension functions, which can unblock a restricted host, although they are slower.
Is this error a security problem?
No. It signals an environment or code mismatch, though a half-broken upgrade is worth checking right away.
Get notified when this fix updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.