tags:

views:

308

answers:

4

With Php when does an included file get included? Is it during a preprocessing stage or is it during script evaluation?

Right now I have several scripts that share the same header and footer code, which do input validation and exception handling. Like this:

/* validate input */
...
/* process/do task */
...
/* handle exceptions */
...

So I'd like to do something like this

#include "verification.php"

/* process/do task */
...

#include "exception_handling.php"

So if include happens as a preprocessing step, I can do the #include "exception_handling.php" but if not, then any exception will kill the script before it has a chance to evaluate the include.

Thanks

+1  A: 

include/require are executed in sequence like 'echo' or other statements.

too much php
+6  A: 

PHP.net: include gives a basic example:

vars.php
<?php

$color = 'green';
$fruit = 'apple';

?>

test.php
<?php

echo "A $color $fruit"; // A

include 'vars.php';

echo "A $color $fruit"; // A green apple

?>

so include happens when its executed in code.

Edit: fixed url.

Tuminoid
A: 

In the order it appears in the code.

John T
+2  A: 

PHP doesn't have a preprocessor. Starting a line with an '#' makes the line a comment. You have to do this to include a file:

include ("exception_handling.php");
include 'exception_handling.php'; // or this, the parentheses are optional

Read this for more information: http://php.net/include

yjerem