Home >Backend Development >PHP Tutorial >Detailed explanation of how to use php include_once
include_once statement includes and runs the specified file during script execution. This behavior is similar to the include statement, the only difference is that if the file has already been included, it will not be included again. As the name of this statement implies, it will only be included once.
include_once can be used when the same file may be included more than once during script execution, and you want to ensure that it is only included once to avoid function redefinition, variable Reassignment and other issues.
See the include documentation for more information.
Note:
In PHP 4, the behavior of _once is different in operating systems that are not case-sensitive (such as Windows), for example:
Example # 1 include_once in PHP 4 running in case-insensitive operating systems
<?php include_once "a.php" ; // 这将包含 a.php include_once "A.php" ; // 这将再次包含 a.php!(仅 PHP 4) ?>
This behavior has been changed in PHP 5, for example in Windows the path is normalized first, so C:\PROGRA~1\A .php has the same implementation as C:\Program Files\a.php, the file will only be included once.
The include_once statement includes and runs the specified file during script execution. This behavior is similar to the include statement, the only difference is that if the file has already been included, it will not be included again. As the name of this statement implies, it will only be included once.
include_once (PHP 4, PHP 5)
The include_once statement includes and runs the specified file during script execution. This behavior is similar to the include statement, the only difference is that if the file has already been included, it will not be included again. As the name of this statement implies, it will only be included once.
include_once can be used when the same file may be included more than once during script execution, and you want to ensure that it is only included once to avoid problems such as function redefinition and variable reassignment.
Include and run the specified file, and the include() function type. The difference is that if the code in the file has already been included, it will not be included again. As the name of this statement implies, it will only be included once.
<?php include_once "a.php"; // this will include a.php include_once "A.php"; // this will include a.php again on Windows! (PHP 4 only) ?>
The above is the detailed content of Detailed explanation of how to use php include_once. For more information, please follow other related articles on the PHP Chinese website!