PHP ???? ??? ???? ????.
?? ????? ????? ?? ?? ??? ??? ??? ?? ??? ?? ???, ??? ??? ???? ??? ? ??? ???? ???. ? ??? ??? ????? ????? ?? ?? ? ?? ??? ? ???? ?????. PHP?? ??? ???? require, require_once, include ? include-once? ? ?? ??? ????.
???? ??? ?????.
函數(shù) | 包含失敗 | 特點(diǎn) |
---|---|---|
Inlcude | 返回一條警告 | 文件繼續(xù)向下執(zhí)行。通常用于動(dòng)態(tài)包含 |
Require | 一個(gè)致命的錯(cuò) | 代碼就不會(huì)繼續(xù)向下執(zhí)行。通常包含極為重要的文件,整個(gè)代碼甭想執(zhí)行 |
Include_once | 返回一條警告 | 除了原有include的功能以外,它還會(huì)做once檢測(cè),如果文件曾經(jīng)已經(jīng)被被包含過,不再包含 |
Require_once | 一個(gè)致命的錯(cuò) | 除了原的功能一外,會(huì)做一次once檢測(cè),防止文件反復(fù)被包含 |
??:
1. ?? ??? ???? ? ? ?? ???? ????? _once? ? ? ?? ?????.
2, Extra Advanced
Include ??? ? ?? ????? ???. include? ??? ??? ?? ??? ?? ???? ?????. .
? ?? ??? ??????.
1. include?? ??? ??? ???? ????.
functions.php ??? ??? ? ?? ? ?? ??? ?????.
<?php //functions.php文件 function demo(){ echo 'aaaa'; } function test(){ echo 'cccdddd'; } ?>
functions.php? ??? ????? user.php ??? ??? ??? function.php ??? ?????. . ?? ??? ? ??? function.php? ????? ??? ? ????. ??? ??? ??? ? ???? ?? ??? ??????.
<?php //user.php include 'functions.php'; //可以直接調(diào)用 demo(); test(); ?>
?? ?? ?? include? ??? ?? ????. ????, include? require? ?????:
???? ?? include? ???? ???? ?? test.php ??
<?php //user.php include 'functions.php'; include 'test.php'; //可以直接調(diào)用 demo(); test(); ?>
? ???? ?? require? ???? ???? ?? test.php ??? ?????. test.php ??:
<?php //user.php include 'functions.php'; require 'test.php'; //可以直接調(diào)用 demo(); test(); ?>
? ??? ???? ??? ??????.
test.php ??? ??? include? ??? ???? ??? ?? ?????( ) ? test() ??.
??? require? ??? ?? ????, ??() ? test() ??? ?? ??? ? ????.
?? ?? ? ? ????. include? include_once? ???? ????? ????? ??? ???? ????. include_once? ????? ???? ?? ??? ? ?? ???? ???, include? ?? ?? ?? ?? ????. ??? ????? ??? ???? ?? ?????.
?? ?? ?? ??? user.php? ?? ??? ?????. ?? include? include_once? ???? function.php? ? ? ?????.
<?php //user.php //這兒被包含了兩次同樣的函數(shù)定義文件喲 include 'functions.php'; include 'functions.php'; //可以直接調(diào)用 demo(); test(); ?>
include_once? ???? ?? ?????.
<?php
<?php //user.php //這兒被包含了兩次同樣的函數(shù)定義文件喲 include_once 'functions.php'; include_once 'functions.php'; //可以直接調(diào)用 demo(); test(); ?>
??? ??? ? - include include? ??? ? ? function.php? ??? ? ?? ??? ??? ?? ??? ? ????:
? ??? ?????? ??() ??? ???? ? ??? ??? ?? ????.
?? ?? ??? ????? ??? ? ? ??? ? ???, ??? ??? ??? ?????. function.php? ? ? ????? ??? ? ? ???? ?? ??? ???????.
include_once? ??? ???? ?? ??? function.php? ??? ?????? ? ?? ???? ???? ?? ???? ?????.
require? require_once? ??? ???? ?? ??? ??? ??? ? ???? require_once?? ? ?? ??? ????.
1. ??? ??? ???? ???. ??? ??? ??? ?????.
2. ???? ?? ??? ?????.