include_once()

简介: include_once() The include_once() 语句在脚本执行期间包括并运行指定文件。此行为和 include() 语句类似,唯一区别是如果该文件中的代码已经被包括了,则不会再次包括。

include_once()

The include_once() 语句在脚本执行期间包括并运行指定文件。此行为和 include() 语句类似,唯一区别是如果该文件中的代码已经被包括了,则不会再次包括。如同此语句名字暗示的那样,只会包括一次。

include_once() 应该用于在脚本执行期间同一个文件有可能被包括超过一次的情况下,你想确保它只被包括一次以避免函数重定义,变量重新赋值等问题。

使用 require_once()include_once() 的更多例子见最新的 PHP 源程序发行包中的 PEAR 代码。

注: include_once() 是 PHP 4.0.1pl2 中新加入的。

 

注: 要注意 include_once()require_once() 在大小写不敏感的操作系统中(例如 Windows)的行为可能不是你所期望的。

例子 16-9. include_once() 在 Windows 下不区分大小写

<?php
include_once("a.php"); // this will include a.php
include_once("A.php"); // this will include a.php again on Windows!
?>

 

 

警告

Windows 版本的 PHP 在 4.3.0 版之前不支持该函数的远程文件访问,即使 allow_url_fopen 选项已被激活。

相关文章
|
2月前
|
编译器 C语言
#include
#include
40 0
|
7月前
makefile include 使用介绍
makefile include 使用介绍
45 0
|
25天前
|
测试技术
常用字符串函数 #include<string.h>与#include<stdio.h>
常用字符串函数 #include<string.h>与#include<stdio.h>
|
2月前
|
存储
include函数
【2月更文挑战第15天】include函数。
18 2
|
3月前
#include 的应用练习
#include 的应用练习。
23 3
|
C++
万能头文件#include<bits/stdc++.h>
#include<bits/stdc++.h>这个头文件的含义
209 1
|
编译器 C++
解决iostream.h在vc2008下不能被include
解决iostream.h在vc2008下不能被include
65 0
|
C语言 C++
C++__#include <cstdio>有什么用?
C++__#include <cstdio>有什么用?
193 0