先编辑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。

最新文章

  1. JMeter学习-025-JMeter 命令行(非GUI)模式详解(三)-测试图形化 HTML 报表(dashboard)生成
  2. 客户端JS性能的一些优化的小技巧
  3. asp.net 加载xml到menu
  4. ThoughtWorks 2016年第1期DNA活动总结
  5. Java基础——数组Array
  6. 二十、ValueStack的常用方法
  7. 【学习笔记】【C语言】标识符
  8. 彻底理解Cisco/Linux/Windows的IP路由
  9. 利用Keil u4调试,精确实现软件延时
  10. Hbase配置中出现的问题总结
  11. WebStorm中Node.js项目配置教程(1)——创建项目
  12. 转 s3c2440硬件学习----内存管理单元MMU
  13. 剑指offer反转链表
  14. 10、借助POI实现Java生成并打印excel报表(1)
  15. [bzoj3910] 火车
  16. Exp1 PC平台逆向破解 20165235 祁瑛
  17. struts2+dojo实现datagrid
  18. Linux 变量的使用
  19. 标准库中 vector list等排序
  20. Codeforces.547C.Mike and Foam(容斥/莫比乌斯反演)

热门文章

  1. cookie 详解 与 封装 实用的cookie
  2. 阿里宣布Atlas正式开源:带你重返App开发的田园时代
  3. 给 Qt 添加模块
  4. MySQL数据库设计总结
  5. java aes encrypt
  6. C++ Primer 5 CH1 开始
  7. 时间相关库&lt;ctime&gt;解析
  8. Meta http-equiv属性详解
  9. js华氏度转为摄氏度
  10. IOS开发创建开发证书及发布App应用(四)——创建配置概要文件