Page 1 of 1

include not working in another file being included

Posted: Tue May 06, 2008 2:42 pm
by kryles
I have a file called Thanks, it includes in the following order 2 files

languagefile.php
incThanks.php

Everything from languagefile.php is not shown on incThanks.php

but when I set it up so incThanks is includes from Thanks.php and languageFile.php is included from incThanks.php it works fine.

err, that was kind of hard to follow so in a diagram it would look like

not working

Code: Select all

 
Thanks.php -> languagefile.php
                -> incThanks.php
 
working

Code: Select all

 
Thanks.php -> incThanks.php -> languageFile.php
 
Anyways I was just wondering why this could be the case. I was under the assumption that the way includes works it makes it as though all the code is just added in, so why couldn't incThanks.php pick up on the languagefile.php code?

Thanks,

Re: include not working in another file being included

Posted: Thu May 08, 2008 5:25 pm
by Jade
The problem you're having is that you cannot includes do not work both ways. For instance, if you are inside of thanks.php and you include incthanks.php then incthanks.php will not have the information from thanks.php. Includes only go one way. Think of an include as taking all of the code that's in it and slapping that into the place you're including it. So if you had something like this:

thanks.php

Code: Select all

 
include(incthanks.php);
echo " world";
 
incthanks.php

Code: Select all

 
echo "hello";
 
When you view the thanks.php page you will see hello world. If you included the inthanks.php AFTER echoing hello you would see world hello. If you viewed the inthanks.php page you would only see hello.