1// Require a file to be imported or quit if it can't be found
2<?php
3 require 'somefile.php';
4?>
5
6// Alternatively: Include a file, if it can't be found: continue.
7<?php
8include 'vars.php';
9?>
1# return.php
2<?php
3
4$var = 'PHP';
5
6return $var;
7
8?>
9
10# noreturn.php
11<?php
12
13$var = 'PHP';
14
15?>
16
17# testreturns.php
18<?php
19
20$foo = include 'return.php';
21
22echo $foo; // prints 'PHP'
23
24$bar = include 'noreturn.php';
25
26echo $bar; // prints 1
27
28?>
29
30//$bar is the value 1 because the include was successful. Notice the difference between the above examples. The first uses return within the included file while the other does not. If the file can't be included, false is returned and E_WARNING is issued.