PHP call to undefined function – Fatal Error
Many PHP developers at least once in their career faced the following error:
Fatal error: Uncaught Error: Call to undefined function
To fix it, you should find the reason why the function happens to be undefined.
Here are the most popular ones:
- You misspelled the function name. E.g. instead of referring to
changeDate()
you referred tochngeDate()
. Make sure the function name is the same as the declared one. - You didn’t include the file with the function properly. If the function is located in the external file, make sure you loaded it with
include()
orrequire_once()
. - You are referring to a PHP function that is not supported with the PHP version installed on your server.
- You used the namespaced method without specifying the namespace (e.g. with
use
).
Example of properly working function:
<?php
function testFunction() {
return "I'm a function!";
}
echo testFunction();
Output: I’m a function!