Question about how INCLUDE and REQUIRE function

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
User avatar
TheTestUser
Forum Newbie
Posts: 9
Joined: Sat Dec 14, 2002 9:25 pm

Question about how INCLUDE and REQUIRE function

Post by TheTestUser »

Is include and require both simply functions that are only called within their own code blocks, or are they parsed out before the script executes?

In other words if I use:

Code: Select all

if ($page = 0)
{  include 'myfile.php';
}
else
{  include 'myotherfile.php';
}
Will inlude only include myfile if $page == 0 or will the PHP engine include both files before executing the code?

The reason I ask is that one of my scripts are getting quite unweildly (8000 lines+) and I'm wondering if pageload time and overhead would be lessed if I split it into several pages that I can include where I needed it.
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

In your example it will only include the one file. Depending on the value. I use includes to break apart many of my pages. For example almost always when i have a page that will pass other variables to the same page like sorting order i will have 2 includes. The main page with nothing passes and then the 2nd part with variables passed. Easier for me to work on one part at a time.
Beans
Forum Commoner
Posts: 49
Joined: Mon Dec 23, 2002 3:06 am
Location: Manila, Philippines
Contact:

Post by Beans »

The includes will only be executed once it has been passed through by PHP. Let's say your include file contains 5 lines of echo statement. After showing the 5 lines, it will then continue on with where it left off.
Post Reply