To import/merge code in PHP, there are functions:
require 'caminho/para/seu/arguivo.php'
require_once 'caminho/para/seu/arquivo.php'
include 'caminho/para/seu/arquivo.php'
include_once 'caminho/para/seu/arquivo.php'
All these functions serve to import code. The only difference between "include
" and "require
" is that they treat possible errors differently.
In a scenario where the file you want to import does not exist, for example:
In the include function, the code will continue running, but an error alert will be displayed on your site.
In the require function, a fatal error (fatal error) will be generated and code execution will stop.
The two variants of the functions, "require_once" and "include_once", mean that PHP will check whether the file has already been included previously, and if so, it will not be included again.
Example:
<?php
require 'meuarquivo.php' // Inclui o arquivo
require_once 'meuarquivo.php' // Não inclui o arquivo de novo, pois ele já fui incluído acima.
?>