Few PHP errors are as confusing the first time you meet them as this one:
PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen()
in /home/user/public_html/index.php:42
Your code looks fine. The function name looks right. Yet PHP stops dead and tells you the function does not exist. The good news is that this error has a short list of causes, and once you know how to read the message, you can find the right one in a couple of minutes. This guide walks through every cause, from the most common to the rare ones, with a fix for each.
What the error actually means
When PHP runs a line like mb_strlen($text), it looks the name up in everything it has loaded: built-in functions, functions from enabled extensions, and functions defined in your own files. If the name is nowhere to be found, PHP throws an Error and the script stops immediately. Nothing after that line runs.
The message itself gives you the two facts that matter most: the exact function name PHP could not find, and the file and line number where the call happened. Start every fix there. Do not guess which function is missing — copy the name from the message.
There is one more detail worth knowing. Since PHP 7, this is an Error, not a warning, so you cannot ignore it or catch it with a normal try/catch (Exception $e). You would need to catch Error, and that is almost never the right fix. The right fix is to find out why the function is missing.
Cause 1: A typo in the function name
This is the simplest cause and the easiest to overlook, because your eyes read what you meant to type, not what you actually typed. One extra or missing letter is enough:
<?php
// This line throws the error — strlenn has an extra "n"
echo strlenn("hello");
// The fix: spell the built-in function correctly
echo strlen("hello");
PHP function names are case-insensitive, so Strlen and strlen are the same function, but spelling is not forgiving. When the error names a function you wrote yourself, search the project for function thatName( and check whether the definition spells it exactly the same way. A quick way to confirm is function_exists():
<?php
var_dump(function_exists('mb_strlen')); // true if PHP knows it, false if not
If function_exists() returns false for a built-in function, the problem is not a typo — it is one of the causes below.
Cause 2: The file that defines the function was never included
Your own helper functions only exist after PHP has loaded the file that defines them. If a script calls format_price() but never includes helpers.php, PHP has no way to know the function exists:
<?php
// Broken: format_price() is defined in helpers.php, which was never loaded
echo format_price(1500);
// Fixed: load the file before the call
require_once __DIR__ . '/helpers.php';
echo format_price(1500);
In a larger project this usually means the Composer autoloader is missing from the entry script. Every request that uses Composer packages should start with:
<?php
require __DIR__ . '/vendor/autoload.php';
Without that line, classes and helper functions from your packages are all undefined, and the first one your code touches produces this exact error. The same thing happens after a partial upload: if helpers.php failed to upload to the server, the function is missing on the server even though it works on your own computer. Re-upload the file and the error goes away.
Cause 3: A PHP extension is not enabled — the most common cause
This is the cause behind most reports of this error, especially on shared hosting and after a PHP version change. Functions like mb_strlen(), curl_init(), imagecreatetruecolor() and mysqli_connect() are not part of PHP's core. Each one belongs to an extension, and if that extension is not enabled for the PHP version your site actually runs, the function does not exist:
| Function in the error | Extension to enable |
|---|---|
mb_strlen(), mb_substr(), mb_strtolower() |
mbstring |
curl_init(), curl_exec() |
curl |
imagecreatefromjpeg(), imagecreatetruecolor() |
gd |
mysqli_connect(), new mysqli |
mysqli |
simplexml_load_string() |
simplexml |
new DOMDocument |
dom |
new ZipArchive |
zip |
NumberFormatter, idn_to_ascii() |
intl |
Check what is loaded before you change anything:
php -m
If the extension you need is not in that list, enable it. On Ubuntu or Debian it is usually a separate package:
sudo apt install php-mbstring
sudo systemctl restart apache2
On cPanel hosting, open Select PHP Version (or MultiPHP Manager), tick the checkbox for the extension, and save. There is no file to edit and no server restart to arrange — the checkbox is the whole fix.
Watch out for the trap that wastes the most time here: the command line and the web server often read different php.ini files and can even run different PHP versions. Running php -m over SSH tells you about the command-line PHP, while your website may run another version through PHP-FPM. Check both: php --ini for the CLI, and a small phpinfo() page for the web version. If you enable the extension in the wrong php.ini, nothing changes and the error stays.
If you are not sure which extension provides a function, look it up on php.net. The manual page for every function sits under the extension that provides it, and if php.net has no page for the name at all, it is not a PHP function — go back to Cause 1 or Cause 2.
Cause 4: The function was removed in a newer PHP version
Sometimes the code is fine and the extension is enabled, but the function simply no longer exists. PHP 8 removed several old functions outright:
<?php
// mysql_connect() was removed in PHP 7 — this line can never work again
$conn = mysql_connect('localhost', 'user', 'pass');
// The modern replacement
$conn = mysqli_connect('localhost', 'user', 'pass', 'mydb');
Other removals from the same era include each(), create_function(), money_format() and the ereg_* family. This cause usually appears right after a PHP upgrade: the site worked on PHP 7.4 and breaks on PHP 8.2 with this error. There is no setting that brings a removed function back. The code has to change to the modern replacement, and the PHP migration guides list a replacement for every removed function.
Cause 5: The function lives in another namespace
Inside a namespaced file, an unqualified call like rupiah(15000) makes PHP look for App\rupiah(), not the global function you meant. Built-in functions still fall back to the global namespace, but your own functions do not:
<?php
namespace App;
// Wrong: PHP looks for App\rupiah(), which does not exist
echo rupiah(15000);
// Right: import the function, or use its full name
use function App\Util\rupiah;
echo rupiah(15000);
If the error message shows a namespace prefix in front of the function name, such as Call to undefined function App\rupiah(), this is your cause. Add the use function import at the top of the file, or call the function with its full name including the leading backslash.
Cause 6: The function is defined inside a conditional, or disabled in php.ini
A function written at the top level of a file is available before the first line runs, but a function written inside an if block only exists after that block has executed. Calling it before the condition runs produces this error:
<?php
// Broken: sapa() does not exist yet — the if block has not run
echo sapa('Ali');
if (true) {
function sapa($name) {
return "Hello, {$name}";
}
}
Move the definition out of the conditional and the error disappears. The same symptom has one more possible source: the disable_functions directive in php.ini. If a host has disabled a function there, PHP treats it as completely unknown, and it can even be redefined. Check the directive with phpinfo() if a standard function is missing for no other reason.
A five-step checklist to find the cause
When the error appears, work through these in order instead of guessing:
- Read the message. Note the exact function name and the file and line number.
- Check the spelling. Compare the name in the message with the PHP manual or your own definition.
- Run
php -m. If it is a built-in function from an extension, confirm the extension is loaded for the version your site runs — CLI and web server checked separately. - Search the project. Confirm the definition exists with
function name(, and that its file is loaded withrequireor the Composer autoloader. - Check the PHP version. If the error started after an upgrade, look the function up in the migration guide — it may have been removed.
Most of the time, step 3 is where the search ends: a missing extension after a version switch or a move to a new host.
How to prevent it
A few habits keep this error from coming back. Use an IDE that knows PHP's built-in functions, so a typo is underlined before you ever run the script. Load code through Composer's autoloader and require_once so definitions are always present when they are needed. Guard calls to functions that may not exist on every server with function_exists() and a fallback. And before changing the PHP version on a live site, run the code on the new version locally first — that is where removed functions and missing extensions show up safely instead of on the live site.
If your API code is hitting this error, it is often the same missing-extension story in a Laravel project — How to Create a REST API in Laravel 13 shows how a Laravel 13 API is put together, and the same extension checks apply there. For another classic PHP error where the message points at the wrong line, see How to Fix "Headers Already Sent" Error in PHP.
Frequently asked questions
Why does the error appear after a PHP upgrade?
Because the new version either removed the function or does not have the same extensions enabled as the old one. Compare php -m on both versions and check the migration guide for removed functions.
Why does the code work on my computer but not on the server?
Because the two environments differ: a different PHP version, a different set of enabled extensions, a file that never uploaded, or a different php.ini. Compare phpinfo() output from both, and the difference is usually visible in seconds.
Can I catch this error and keep going?
Technically yes, by catching Error instead of Exception, but that only hides the problem. The function is still missing, so the feature that needed it still cannot work. Fix the cause instead.
Is this error the same as "Class not found"? No, but it is closely related. "Call to undefined function" is about a missing function; "Class not found" is about a missing class, and in Laravel it usually means a missing import or a wrong namespace. Both are fixed by finding what PHP cannot see and making it visible.

