In Php when evaluating Include / Require?

With Php, when is the included file included? Is it during the preprocessing phase or during the evaluation of the script?

I currently have several scripts that use the same header and footer code that do input validation and exception handling. Like this:

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

      

So, I would like to do something like this

#include "verification.php"

/* process/do task */
...

#include "exception_handling.php"

      

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

thank

+1


source to share


4 answers


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 inclusion happens when it's done in code.

Edit: fixed url.

+8


source


PHP has no preprocessor. Running a line with a "#" character makes a comment line. You must do this to include the file:

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

      



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

+3


source


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

+1


source


In the order shown in the code.

0


source







All Articles