include not working in another file being included

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

include not working in another file being included

Post 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,
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: include not working in another file being included

Post 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.
Post Reply