Troubleshooting

Fix PHP Fatal error: Call to undefined function

Fix "Call to undefined function" errors in PHP: missing extensions like mysqli, curl, mb_ or gd, functions removed in PHP 8, missing includes and wrong namespaces.

IntermediatecPanel hosting · Linux VPS2 min read

Call to undefined function means PHP was asked to run a function it does not know. There are three usual causes: the extension that provides the function is not loaded, the function was removed in your PHP version, or the file that defines it was never included.

Before you start

  • Copy the exact error from the log, including the function name.
  • Know which PHP version the site uses. A phpinfo() page or the control panel will show it.

Identify where the function comes from

Function prefixExtension to enable
mysqli_*mysqli
curl_*curl
mb_*mbstring
imagecreate*, getimagesize on some formatsgd
simplexml_*, dom_*xml / dom
zip_*zip
bcadd, bcmulbcmath
intl*, numfmt_*intl
sodium_*sodium

Enable the missing extension

  • cPanel with CloudLinux: Software → Select PHP Version → Extensions, tick the extension and save.
  • cPanel without CloudLinux: ask support, or on your own server use WHM → EasyApache 4.
  • VPS: install the package, for example sudo apt install php8.3-mbstring, then restart PHP-FPM.

Step-by-step instructions are in PHP extensions in cPanel and install PHP extensions on Linux.

Check the result from the command line with php -m | grep -i mbstring. The CLI and the web server can use different PHP versions, so check the website too.

Functions removed in newer PHP versions

Old functionRemoved inUse instead
mysql_connect, mysql_queryPHP 7.0mysqli_* or PDO
ereg, splitPHP 7.0preg_match, preg_split
create_functionPHP 8.0Anonymous functions
eachPHP 8.0foreach
money_formatPHP 8.0NumberFormatter (intl)
utf8_encode, utf8_decodeDeprecated in 8.2mb_convert_encoding

If old code calls these, update the plugin or script. As a short-term workaround only, run the site on an older supported PHP version. See the PHP version upgrade checklist.

Your own or a plugin's function is undefined

  • The file that defines it is not included. Check the require/include paths and whether Composer's vendor/autoload.php is loaded.
  • The function lives in a namespace. Call it as \Vendor\Package\func() or add use function Vendor\Package\func;.
  • The plugin that provides it is deactivated, while another plugin still calls it.

FAQ

The extension is enabled but the error remains. Why?

You probably enabled it for a different PHP version or handler than the one the site uses. Compare the version in phpinfo() on the website with the one you changed.

Why does it work in the browser but fail in cron?

Cron uses the CLI PHP, which may be a different version with other extensions. Call the full path of the right PHP binary in the cron command.

Is undefined method the same error?

Not quite. "Call to undefined method" means a class exists but lacks that method, usually because of a library version mismatch. Update the dependencies with Composer.

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.