From the course: Learning PHP

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

include_once and require_once

include_once and require_once - PHP Tutorial

From the course: Learning PHP

Start my 1-month free trial

include_once and require_once

- [Instructor] There are two other functions to help you include files, include once and require once. These files work exactly the same as include and require, except that if the file in question has already been included, these functions return the value true and the file isn't included again. This is great if you want to make sure you're not including a set of functions or a class more than once, because PHP throws an error if you try to redefine these functions or classes. So let's take a look at a quick example. You can see, I have my index page on the screen here and in the inc folder, there is a new file called functions.php. In functions.php I've got two functions, pre-print and para print to do some of the things we've been doing a lot. And if I go back to include, I can add it here on the page, I'll do it above the variables file inclusion. And first I'll use require here. So we'll say require…

Contents