This applies to PHP CLI (command line interface) on Windows and linux. This is not a problem when using PHP via HTTP.
I am getting a PHP Fatal error: Call to undefined function when I put a function in a separate file.
This is regardless of using include, require, or require_once.
The code works great if I have the functions in the same file, but that's not practical.
Example
runMe.php
<?php
var_dump($argv); //<----command line - array of arguments
if(file_exists('functions.php')) require_once('functions.php'); //<--- load functions
testme(); //<---- call function
?>
functions.php The testme() function does nothing.
<?php
function testme(){
//do nothing
}
?>
The following suggestion does not work: php -r "include('functions.php'); testme();" Found at: How to call a PHP function from CLI?
Another suggestion (creating a class) does not work either: How do you execute a method in a class from the command line
All other suggestions that I found used include and require.