先编辑command.php文件
?
|
1
|
echo 'hello'.PHP_EOL;
|
然后编辑console.php文件
?
|
1
2
3
|
|
原本想要包含并执行这个echo,没想到写错了文件名,如果是require,会报出这样的错误:
?
|
1
2
3
4
5
|
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
?
|
1
2
3
|
for($i=1;$i<=3;++$i){
include 'command1.php';
}
|
会报出这样的错误:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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。
原文链接:http://www.cnblogs.com/sweng/p/6749496.html
相关文章
猜你喜欢
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
云服务器上建站:操作系统选型(Linux vs Windows)的影响
2025-06-04 45 -
2025-05-25 69
-
2025-05-25 46
-
2025-05-29 59
-
2025-06-04 86
热门评论

