I know this subject has been discussed in SO but yet I wasn’t able to find a solution.
I have assign.php:
$a=1;
require.php:
require "assign.php";
and echo.php:
require "require.php"
echo $a;
which outputs 1.
problem is, when I want to use “require.php” from a different location, without having duplicate files. for example,
/folder/echo.php:
require "../require.php";
echo $a;
won’t work, since require.php is trying to require /folder/assign.php which doesn’t exist.
Trying to use a full url in require.php:
require "http://site.com/assign.php";
won’t work either because the code isn’t being included, but compiled, and since $a is not global, it is undefiend.
I was told by some that using globals is really not recommended.
Also using a filesystem full path is said to be dangerous.
What is the solution? How can I make sure require.php will always go for the right path for assign.php, no matter where require.php is included from?
You could define a global constant and use that.