Q:

echo variable with variable from included file

so basically what I can't get through is to echo a variable, that contains variable from included file.
Explanation:
I have 3 files:
index.php
system/functions.php
system/config.php

each file is including the other file so they work like one (except index)
system/functions.php contains:
include_once $_SERVER['DOCUMENT_ROOT'].'/system/config.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/system/connection.php';

system/config.php contains:
include_once $_SERVER['DOCUMENT_ROOT'].'/system/functions.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/system/connection.php';

there's nothing wrong with it and they work together without problems, they can pass variables between themselves successfuly. BUT
When I want to:
echo $message;

On the index.php, the output is only the string from the variable, and skips other variables from included files...
In this case, the functions.php file contains
$message = $varfromconfig."Some String";

where config.php contains
$varfromconfig = "someword ";

and when I echo the $message to index page, only the string Some String is returned, without the config variable... Why? (Should return someword Some String)
Thank you.
Of course, the index.php contains both the config and the functions...
include_once 'system/config.php';
include_once 'system/connection.php';
include_once 'system/functions.php';

A:

Do this at index.php:
//include_once 'system/config.php'; remove this include from index.php
include_once 'system/connection.php';
include_once 'system/functions.php';

OR, do this:
include_once 'system/config.php'; remove this include from index.php
include_once 'system/connection.php';
include 'system/functions.php'; //not include_once

You have a loop when you insert both. I imagine your relation between config.php and functions.php can be more complex then you wrote here, so I will try to detail what is happening so you can find another solution, if needed.
Right after you run index.php, it calls for config.php. Then, inside config.php, this happens:
config.php insert functions.php, but then functions.php insert config.php, and config.php insert funtions.php again and this will keep forever. So php interpreter just break the loop before it happens and import only functions.php from inside config.php, but don't import config.php from inside functions.php from inside config.php. (damn inception)
So now we have just passed line 1 of index.php and have imported first config.php from index.php and then functions.php from config.php. The interpreter had first red functions.php, loaded its variables, then went to config.php and loaded its variables.
Thus, first from functions.php, it runs $message = $varfromconfig."Some String";. Once config.php wasn't interpreted yet and $varfromconfig is still empty, it assing "Some String" to $message. Then it runs $varfromconfig = "someword ";, but without having it assigned to $message, because $message assignment was already done.
On the seccond line, connections.php is imported, and then on third line it tries to import functions.php, but functions.php was already inserted. So include_once don't let it be imported.
To solve this, once the variable in functions.php require config.php to run first, you just call for functions.php at index.php and let functions.php call config.php by itself. The other solution is to use include and not include_once to insert functions.php and let it be interpreted two times.

