In PHP there are several ways to add files into others using:
require()
require_once()
include()
include_once()
But is there any difference between them?
Are there specific cases where it is better to use one or the other?
The objective of the question is to have a clear idea about whether in some cases it is convenient to use one or the other, to have a more optimized code taking into account the consumption of resources or other criteria, for this reason, it is convenient that in the answer it is indicated if the use of one or the other affects to a greater or lesser degree the amount of memory that is consumed or other important details.
include
require
Include_once and Require_once
Final conclusion:
We can think of using include when the file to be inserted is not decisive regarding the operation of our program. Require when said file is necessary for the correct functioning of our program.
Finally, the variants with _once should be used when our program has considerable dimensions and it may be the case that the inclusion of the file occurs several times. These last variants must be used only in exceptional cases since they consume more resources than the previous ones.
According to the official PHP documentation :