· PHP – Syntax – Statements – Script Inclusion
- Script Inclusion
statements allow you to include content of another single PHP script.
script which is being included must have proper PHP tags, like <?php ... ?>,
which will not be copied.
- Result of script inclusion statements is one huge PHP script in
which content of other PHP scripts was copied.
- Each PHP script might have it's own namespace which has
nothing to do with the name of the file or its actual location.
Before the script is copied, namespace is used to create
full class names and only then the file is copied.
- This tutorial is based on:
- Script – Referencing:
- By filename in which case it will be looked for in each of
the directories listed in include_path:
- By relative path in which case it will be looked for
relativly to each of the directories listed in include_path:
require_once 'Vehicles\MyClass.php'; //In
require_once '..\Vehicles\MyClass.php'; //In directory Vehicles in
- By absolute path in which case it will be looked for only
in that specific location:
- Script – Locating:
- PHP will use the first file that it finds checking include_path
directories from left to right:
- If file is not found PHP will check once more positioning
itself at the current directory ".".
Current directory "." is directory which contains
PHP file where include/require statement was used.