phpfunctioninclude-path

Php include not working? function not being included


Here is the full context of the situation:

I recently got a new Mac, I'm a php developer so I downloaded MAMP and started developing.

First I noticed that my includes were not being included, but I changed that by configuring my php.ini.

However now, when I try to include a file with a function it does not recognize the function.

For example I have a file named functions.php:

<?php
function doit(){
    echo "did it";
}
?>

and a file that includes it called index.php

<?php include("functions.php"); doit();?>

and I get this error message

Fatal error: Call to undefined function doit() in index.php on line 4


Solution

  • So if anyone ever stumbles on this forum because they are having the same issue let me explain what and why it went wrong.

    If you include a function not in your directory(e.g c:// or file://) but instead include using http. The include can only return what was echoed in the file, but something like a variable or function will not be shown. So always include functions and variables through a directory