So, my code was using relative paths, but running into some problems with common files which could be include/required from different directory levels.
Absolute paths are more efficient anyway, right? So, I changed all include/require to absolute paths, using require_once('http://' . $_SERVER['HTTP_HOST'] . 'file_name.php');
$_SERVER['HTTP_HOST'] is correct, isn’t it? It seemed so when I googled.
That required me to set ‘allow_url_include=on` in php.ini and restart Apache.
So, now I have a situation that looks something like this (simplified example):
File2.php contains
<?php
function hello()
{
echo 'hello<br>';
}
?>
and if file1.php contains
<?php
require_once('file2.php');
hello();
?>
then I see the expected output “hello”, but if I change that line to
require_once('http://' . $_SERVER['HTTP_HOST'] . '/file2.php');
Then I get “Fatal error: Call to undefined function hello() in C:\xampp\htdocs\file1.php”
(I guess that the reference to c:\xammp\httdos came from Xdebug, because PhpInfo shows HTTP_HOST localhost)
Anyway, that’s a long post to say that I am missing some simple point and to ask what it is.
require_once expects a path on the server and not a URL. So for example you can’t pass http://www.foo.com/test.php but you can do /var/www/foo/test.php. If you put http:// path then it will only include the output and not the php functions.