Recent Posts

How to solve: Fatal error: Call to undefined function

This happens when you try to call a function that is not defined yet. Common causes include missing extensions and includes, conditional function declaration, function in function declaration or simple typos.
Example 1 - Conditional Function Declaration
$someCondition = false;
if ($someCondition === true) {
    function fn() {
        return 1;
    }
}
echo fn(); // triggers error
In this case, fn() will never be declared because $someCondition is not true.
Example 2 - Function in Function Declaration
function createFn() 
{
    function fn() {
        return 1;
    }
}
echo fn(); // triggers error
In this case, fn will only be declared once createFn() gets called. Note that subsequent calls to createFn() will trigger an error about Redeclaration of an Existing function.
In case of a missing extension, install that extension and enable it in php.ini. Refer to the Installation Instructions in the PHP Manual for the extension your function appears in.
In case of missing includes, make sure to include the file declaring the function before calling the function.
In case of typos, fix the typo.

No comments:

Post a Comment