久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP中include和require的區別實例分析

網上太多關于PHP中include與require區別。然而事實真的如此嗎,今天我們就通過一個具體的實例來簡單分析驗證下

先編輯command.php文件

echo 'hello'.PHP_EOL;

然后編輯console.php文件

for($i=1;$i<=3;++$i){
	require 'command1.php';
}

原本想要包含并執行這個echo,沒想到寫錯了文件名,如果是require,會報出這樣的錯誤:

Warning: require(command1.php): failed to open stream: No such file or directory in console.php on line 4

Fatal error: require(): Failed opening required 'command1.php' (include_path='.') in console.php on line 4
PHP Warning: require(command1.php): failed to open stream: No such file or directory in console.php on line 4
PHP Fatal error: require(): Failed opening required 'command1.php' (include_path='.') in console.php on line 4

如果把require改為include

for($i=1;$i<=3;++$i){
	include 'command1.php';
}

會報出這樣的錯誤:

Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4

Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4

Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4

Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4

Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4

Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4
PHP Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4
PHP Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4
PHP Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4
PHP Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4
PHP Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4
PHP Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4

如果使用require_once或者include_once,只要包含路徑正確,那么循環只執行一次。

總結:

使用require,如果文件沒有包含成功,就會報出一個fatal error,整個程序就中止了。

使用include,如果文件沒有包含成功,就會報出一個普通的warning,之后的代碼仍會執行。

如果你的Web程序使用了MVC這種對文件包含強依賴的設計方法,請使用require_once。

【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。

相關文檔推薦

主站蜘蛛池模板: 欧美一级欧美一级在线播放 | 亚洲精选一区二区 | 国产精品成人一区二区三区 | 久久成人人人人精品欧 | 久久久久久成人 | 一本一道久久a久久精品综合 | 奇米四色影视 | 亚洲欧洲一区二区 | 日韩中文字幕一区 | 在线免费看毛片 | 国产精品久久久久久久三级 | 99中文字幕 | 精品国产精品三级精品av网址 | 先锋资源站 | 亚洲成人一区 | 日韩不卡一区二区 | 日韩欧美国产一区二区三区 | 人人做人人澡人人爽欧美 | 欧美一区二区三区四区五区无卡码 | 欧美日韩久久精品 | 粉嫩粉嫩芽的虎白女18在线视频 | 中文字幕亚洲视频 | 91在线免费观看网站 | 成人免费激情视频 | 青青久久av北条麻妃海外网 | 亚洲国产成人久久综合一区,久久久国产99 | 欧美精品一区二区在线观看 | 男女网站免费 | 一区二区三区四区在线视频 | 国产99久久精品 | 国精日本亚洲欧州国产中文久久 | 亚洲网视频| 午夜资源| 国产美女在线播放 | 成人免费在线 | 久久精品久久久久久 | 久久国产精品-国产精品 | 免费黄色片在线观看 | 亚洲高清视频在线观看 | 中文字幕在线观看成人 | 成人亚洲综合 |