Where does function_exists() look to decide whether a function exists? [closed]

function_exists('f') will check if a function f was declared before the call to function_exists. Therefor the direct answer to your question is – in the functions section of the interpreter memory.

The result of function_exists do not only depend on the file in which the function is declared and the file in which the call is made but on the execution path.

function a() {}
-- at another file executed later
echo function_exists('a');

// displays true

while

echo function_exists('a');
// display false;
-- at another file executed later
function a() {}

function_exists at the same file as the function definition (which is a trivial not interesting use case) will always return true because the interpreter parses all function before starting to execute the file.

Adding to the fun is the fact that nested functions are defined only when their parent is evaluated and all php function are in the global scope which might lead to

function a() {
  function b() {}
}

echo function_exists('b');

// displays false

while

function a() {
  function b() {}
}

a();
echo function_exists('b');

// displays true

In a big and complex code like wordpresss it is not trivial to predict the result of function_exists which is probably why core doesn’t use this pattern any longer. If you have the choice you should use hooks instead.