PHP中include與require有什么區別-創新互聯

PHP中include與require有什么區別?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

成都創新互聯主營昌平網站建設的網絡公司,主營網站建設方案,成都app軟件開發公司,昌平h5微信平臺小程序開發搭建,昌平網站營銷推廣歡迎昌平等地區企業咨詢

先編輯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。

看完上述內容,你們掌握PHP中include與require有什么區別的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注創新互聯行業資訊頻道,感謝各位的閱讀!

當前名稱:PHP中include與require有什么區別-創新互聯
網址分享:http://m.kartarina.com/article38/cddgsp.html

成都網站建設公司_創新互聯,為您提供標簽優化關鍵詞優化品牌網站設計全網營銷推廣網站改版網站維護

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都定制網站網頁設計
主站蜘蛛池模板: 亚洲色中文字幕无码AV| 国产成人精品无码片区在线观看 | 亚洲av无码片vr一区二区三区| 亚洲精品无码aⅴ中文字幕蜜桃| 亚洲av成人中文无码专区| 国产精品无码av片在线观看播| 久久无码AV中文出轨人妻| 精品无码无人网站免费视频| 无码精品A∨在线观看无广告| 无码人妻精品一区二区三区久久| 免费无码黄网站在线观看| 亚洲综合无码一区二区三区| 国产精品va在线观看无码| 内射精品无码中文字幕| 亚洲AV无码乱码国产麻豆穿越| 精品人妻少妇嫩草AV无码专区| 亚洲精品无码久久久久YW| 丰满熟妇人妻Av无码区| 亚洲国产av无码精品| 日韩乱码人妻无码中文视频| 亚洲日韩国产精品无码av| 国产精品免费无遮挡无码永久视频 | 亚洲精品一级无码中文字幕| 永久免费AV无码国产网站| 久久精品九九热无码免贵| 国模GOGO无码人体啪啪| 波多野结AV衣东京热无码专区| 无码人妻精品一区二区三区久久久| 久久亚洲精品成人无码网站| 亚洲AV无码成人网站久久精品大| 国产精品亚洲αv天堂无码| 国产精品爽爽V在线观看无码| 成人无码精品一区二区三区| 人妻中文字幕AV无码专区| 韩国无码AV片在线观看网站| 国产精品无码专区AV在线播放| 国内精品久久久久久无码不卡| 色综合99久久久无码国产精品| 久久国产精品成人无码网站| 国产精品无码MV在线观看| 国产精品成人99一区无码|