Okey so the answers here are actually not entirely correct; in some sense even misleading.
include
takes the contents of the file and places them in context. One of the more common uses is to pass variable scope around, ie. passing scoped variables in your view by including them in the handler and using include
on the view. Common, but there are also other uses; you can also return
inside a included
file.
Say you have a file like this:
<?php return array
(
'some',
'php'
'based'
'configuration',
'file'
); # config
Doing $config = include 'example-config-above.php';
is perfectly fine and you will get the array above in the $config
variable.
If you try to include a file that doesn't have a return
statement then you will get 1
.
Gotcha Time
You might think that include 'example-config-above.php';
is actually searching for the file in the directory where the file calling the include
is located, well it is, but it's also searching for the file in various other paths and those other paths have precedence over the local path!
So if you know you had a file like the above with a return
inside it, but are getting 1
and potentially something like weird PEAR errors or such, then you've likely done something like this:
// on a lot of server setups this will load a random pear class
include 'system.php'
Since it's loading a file with out a return you will get 1
instead of (in the case of our example) the configuration array we would be expecting.
Easy fix is of course:
include __DIR__.'/system.php'