php5版本中include和require的区别

在网上看到很多资料,说include和require的区别大致有这么三个。
1.require在无论任何条件下都强制调用。
2.require没有返回值
3.require在错误的情况下,会导致一个致命错误,并停止处理页面。而include只是产生一个警告,继续处理页面。

大家对require的印象就是处理速度较快,在大多数情况下都采用include。

 

当我看到那些文章后,进行一一测试,非常不凑巧,网上的那些文章都得不到很好的验证。
我用的是php5,所以我猜想可能php5对include和require进行了调整吧。
查了下手册最后才知道:


You can insert the content of one PHP file into another PHP file before the server executes it, with the include() or require() function.

The two functions are identical in every way, except how they handle errors:

include() generates a warning, but the script will continue execution
require() generates a fatal error, and the script will stop

 

It is recommended to use the require() function instead of include(), because scripts should not continue after an error.

 

 

 

这下清楚了!

这两种结构除了在如何处理失败之外完全一样。include()   产生一个警告而require()则导致一个致命错误。换句话说,如果你想在遇到丢失文件时停止处理页面就用require()。include()就不是这样,脚本会继续运行。官方推荐使用require()。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值