时间:2021-05-26
先编辑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 4Fatal error: require(): Failed opening required 'command1.php' (include_path='.') in console.php on line 4PHP Warning: require(command1.php): failed to open stream: No such file or directory in console.php on line 4PHP 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 4Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4PHP Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4PHP Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4PHP Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4PHP Warning: include(): Failed opening 'command1.php' for inclusion (include_path='.') in console.php on line 4PHP Warning: include(command1.php): failed to open stream: No such file or directory in console.php on line 4PHP 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。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
在PHP变成中,include()与require()的功能相同,include(include_once)与require(require_once)都是把把
本文实例讲述了PHP实现懒加载的方法。分享给大家供大家参考。具体分析如下:寻常php的加载是通过include(),require()等方法来加载外部文件,之后
一、php中实现自动加载的方法1.使用require,include,require_once,include_once手工进行加载。2.使用__autoloa
前言include和require是PHP中引入文件的两个基本方法。在小规模开发中直接使用include和require没哟什么不妥,但在大型项目中会造成大量的
四种语句PHP中有四个加载文件的语句:include、require、include_once、require_once。基本语法require:require