Detailed explanation of how to use php include_once

黄舟
Release: 2023-03-11 12:24:02
Original
5884 people have browsed it

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)
?>
Copy after login

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)
?>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!