include_once 能够用于在剧本实行时期同一个文件有能够被包括凌驾一次的情况下,想确保它只被包括一次以防止函数重定义,变量从新赋值等题目。
Note:(引荐进修:PHP编程从入门到通晓)
在 PHP 4中,_once 的行动在不辨别大小写字母的操作系统(比方 Windows)中有所不同,比方:
include_once 在 PHP 4 运转于不辨别大小写的操作系统中
<?php include_once "a.php"; // 这将包括 a.php include_once "A.php"; // 这将再次包括 a.php!(仅 PHP 4) ?>
此行动在 PHP 5 中改了,比方在 Windows 中途径先被规格化,因而 C:\PROGRA~1\A.php 和 C:\Program Files\a.php 的完成一样,文件只会被包括一次。
include和include_once:
include载入的文件不会推断是不是反复,只需有include语句,就会载入一次(纵然能够涌现反复载入)。
而include_once载入文件时会有内部推断机制推断前面代码是不是已载入过。
这里须要注重的是include_once是依据前面有没有引入雷同途径的文件为推断的,而不是依据文件中的内容(即两个待引入的文件内容雷同,运用include_once照样会引入两个)。
//test1.php <?php include './test2.php'; echo 'this is test1'; include './test2.php'; ?> //test2.php <?php echo 'this is test2'; ?> //效果: this is test2this is test1this is test2 //test1.php <?php include './test2.php'; echo 'this is test1'; include_once './test2.php'; ?> //test2.php <?php echo 'this is test2'; ?> //效果: this is test2this is test1 //test1.php <?php include_once './test2.php'; echo 'this is test1'; include './test2.php'; ?> //test2.php <?php echo 'this is test2'; ?> //效果: this is test2this is test1this is test2 //test1.php <?php include_once './test2.php'; echo 'this is test1'; include_once './test2.php'; ?> //test2.php <?php echo 'this is test2'; ?> //效果: this is test2this is test1
以上就是php怎样完成include_once的细致内容,更多请关注ki4网别的相干文章!