Page 1 of 1

Question about how INCLUDE and REQUIRE function

Posted: Mon Dec 30, 2002 5:45 pm
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.

Posted: Mon Dec 30, 2002 6:45 pm
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.

Posted: Tue Dec 31, 2002 8:40 am
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.