PHP Programming/PHP Include Files

Includes
There are two methods of including a file in PHP:  and.

They both perform essentially the same function, but have one major difference:  will only throw a warning if there is a problem during the include process; , however, will halt execution in this scenario. Therefore, a script's dependencies will often be called with.

Prior to version 4.0.2,  also attempted to read a file, regardless of whether the code in that file was executed or not. This means that if a file did not exist, an error would be thrown even if it would never be interpreted. The following code:

would therefore fail on the first  in versions before 4.0.2, and the second in all other versions.

Include Once
Additionally, there exist many code libraries, class definitions, and variable declarations that you will want to separate into an include file, but that should only be called into the current script once. To ensure that these libraries are only included once, php includes the  and  functions.

Each time one of these functions is called, the php parser remembers which file it has called. If another or   attempts to load the same file, the parser will simply skip the command. It will produce no error or warning, it will simply act as though the command had executed successfully. This is because, in fact, it has.

IMPORTANT: If you include a file once with  and then later using , the file will be included a second time. If a file is included using  and a call to the same file is made by , it will not be included again. Include_once and require_once have the same 'memory,' as it were.