Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Instead of writing all our code in a single file, PHP allows us to INCLUDE other files, so they function as part of the current page, while keeping them separate. This is very useful for organization and not repeating code for things such as footers and navigation.
How includes work
Included files act as if you had pasted the code directly into the file. Any variables that have already been defined in the main file such as display_name can be utilized and CHANGED. If the file cannot be included PHP will give an error, but continue to process the script. If you want to guarantee that the file is included before continuing on, you should use 'require'.
Documentation
include - includes and evaluates the specified file.
include_once - the only difference being that if the code from a file has already been included, it will not be included again, and include_once returns TRUE. As the name suggests, the file will be included just once.
require - is identical to include except upon failure it will also produce a fatal error. In other words, it will stop the script whereas include only emits a warning which allows the script to continue.
require_once - identical except PHP will check if the file has already been included, and if so, not include it.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Nicholas Pena
933 Points3 Answers
-
Arikaturika Tumojenko
8,897 Points1 Answer
-
Arikaturika Tumojenko
8,897 Points1 Answer
-
Arikaturika Tumojenko
8,897 Points1 Answer
-
nico dev
20,364 Points1 Answer
-
Sara Spring
6,826 Points4 Answers
-
Alvin Hue
4,496 PointsI find it hard to test run php file on my laptop, may I know how can I quickly test run my php code on my laptop?
Posted by Alvin HueAlvin Hue
4,496 Points2 Answers
-
Aaron Coursolle
18,014 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up