Php include not working? function not being included

Php include not working? function not being included

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Php include not working? function not being included

If you are seeing a Fatal error: Call to undefined function immediately after fixing your include statements, the issue likely isn't with the inclusion mechanism itself. It is almost certainly an environment configuration problem, specifically related to how PHP loads its core files on your new machine.

You mentioned that your includes stopped working initially until you configured php.ini. This suggests you were likely setting the include_path or modifying the open_basedir restriction. However, once those changes took effect, the specific error regarding the undefined function indicates a different layer of the stack is failing to load correctly.

When PHP parses your script, it processes files sequentially. If index.php tries to call doit() before the file containing that definition is loaded into memory, the function remains undefined. This usually happens when the physical path to functions.php is incorrect, or when PHP is running in a mode where it cannot find the file at all, causing the script execution to halt before reaching the function definition if they were swapped (which isn't the case here) or simply failing to register the namespace/function space.

However, there is a more subtle and common culprit when dealing with local development environments like MAMP on macOS: the distinction between the CLI interpreter and the web server handler.

If you configured your php.ini by editing the file associated with the command line (/usr/local/bin/php or /usr/local/sbin/php-fpm), but MAMP is still using a different configuration file (often located in /Applications/MAMP/Library/etc/php.ini or a version-specific folder like 5.6, 7.4, etc.), your changes never take effect for the web server. You might think you are running code in one environment, but PHP is actually executing with a pristine default configuration where your custom includes or path settings were applied elsewhere.

To diagnose this, check which binary MAMP is actually invoking. Open your terminal and run:

php -r "echo php_ini_loaded_file();"

Compare the output path with the php.ini file you edited. If they differ, MAMP is ignoring your configuration changes. You need to ensure the include_path directive in the active MAMP configuration points to the directory containing your functions.php. Alternatively, using an absolute path in your include statement can bypass path resolution issues entirely:

include '/var/www/html/public/functions.php'; // or wherever your project root lives

Another frequent pitfall involves file permissions. Even if the path is correct and the config is loaded, macOS might deny the web server process (which usually runs as _www on MAMP) permission to read the file. Run ls -l functions.php in your terminal. If the permissions show -rw-r--r--, the owner might be you, not the group or user running MAMP. Ensure the file is readable by everyone (chmod 644 functions.php) or that the web server user has access to the parent directory.

There is also the matter of syntax errors within functions.php preceding the function definition. If there is a missing semicolon, an unclosed string, or a parse error before function doit(), PHP will throw a fatal error during parsing and might not register the function even if the file loads successfully in a different context. Ensure that functions.php has no syntax errors by running:

php -l functions.php

If you prefer managing dependencies dynamically rather than relying on static includes, consider using Composer for autoloading. This approach decouples your code structure from manual include statements and ensures classes and functions are registered correctly based on the PSR-4 or PSR-0 standard. While this adds a build step, it eliminates the guesswork associated with relative paths and configuration mismatches.

If you are migrating to a larger framework ecosystem where these low-level path issues persist, platforms like Laravel handle dependency injection and file loading through robust service containers. For more complex routing or modular architecture needs, exploring modern frameworks can provide a structured alternative to manual file management. Resources such as https://laravelcompany.com offer insights into building scalable applications where file inclusion is abstracted away in favor of cleaner composition.

Ultimately, the Call to undefined function error after a config change points to a mismatch between your environment's actual PHP process and the settings you believe are active. Verify the binary, check permissions, and ensure syntax integrity before assuming the include logic itself is flawed.

Our network