先编辑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的区别
# php使用include
# 和require引入文件的区别
# php使用include 和require引入文件的区别
# PHP中include()与require()的区别说明
# PHP中include/require/include_once/require_once使用心得
# 简单谈谈PHP中的include、include_once、require以及require_onc
# PHP中require和include路径问题详解
# PHP包含文件函数include、include_once、require、require_once
# PHP中include与require使用方法区别详解
# php include和require的区别深入解析
# PHP中include和require的使用详解
# 就会
# 错了
# 请使用
# 一个普通
# 仍会
# 没想到
# 使用了
# lt
# require
# failed
# open
# bash
# Warning
# console
# pre
# class
# command
# php
# brush
# echo
相关文章:
如何通过IIS搭建网站并配置访问权限?
建站之家VIP精选网站模板与SEO优化教程整合指南
如何用PHP快速搭建CMS系统?
如何生成腾讯云建站专用兑换码?
深圳防火门网站制作公司,深圳中天明防火门怎么编码?
建站之星如何实现PC+手机+微信网站五合一建站?
洛阳网站制作公司有哪些,洛阳的招聘网站都有哪些?
如何快速查询网址的建站时间与历史轨迹?
高性能网站服务器配置指南:安全稳定与高效建站核心方案
大连企业网站制作公司,大连2025企业社保缴费网上缴费流程?
哈尔滨网站建设策划,哈尔滨电工证查询网站?
保定网站制作方案定制,保定招聘的渠道有哪些?找工作的人一般都去哪里看招聘信息?
存储型VPS适合搭建中小型网站吗?
建站主机类型有哪些?如何正确选型
5种Android数据存储方式汇总
如何快速搭建个人网站并优化SEO?
如何注册花生壳免费域名并搭建个人网站?
香港服务器网站测试全流程:性能评估、SEO加载与移动适配优化
如何快速搭建安全的FTP站点?
香港服务器部署网站为何提示未备案?
齐河建站公司:营销型网站建设与SEO优化双核驱动策略
建站之星五站合一营销型网站搭建攻略,流量入口全覆盖优化指南
建站之星展会模板:智能建站与自助搭建高效解决方案
如何基于云服务器快速搭建个人网站?
如何制作网站标识牌,动态网站如何制作(教程)?
邀请函制作网站有哪些,有没有做年会邀请函的网站啊?在线制作,模板很多的那种?
成都网站制作公司哪家好,四川省职工服务网是做什么用?
网站制作与设计教程,如何制作一个企业网站,建设网站的基本步骤有哪些?
北京专业网站制作设计师招聘,北京白云观官方网站?
如何快速搭建高效香港服务器网站?
如何在Golang中指定模块版本_使用go.mod控制版本号
如何在阿里云虚拟服务器快速搭建网站?
香港服务器建站指南:外贸独立站搭建与跨境电商配置流程
学校为何禁止电信移动建设网站?
微信小程序 五星评分(包括半颗星评分)实例代码
子杰智能建站系统|零代码开发与AI生成SEO优化指南
岳西云建站教程与模板下载_一站式快速建站系统操作指南
如何在建站宝盒中设置产品搜索功能?
西安制作网站公司有哪些,西安货运司机用的最多的app或者网站是什么?
定制建站流程解析:需求评估与SEO优化功能开发指南
实惠建站价格推荐:2025年高性价比自助建站套餐解析
常州自助建站工具推荐:低成本搭建与模板选择技巧
建站主机与服务器功能差异如何区分?
建站中国官网:模板定制+SEO优化+建站流程一站式指南
如何在服务器上三步完成建站并提升流量?
实例解析Array和String方法
网站图片在线制作软件,怎么在图片上做链接?
建站之星如何保障用户数据免受黑客入侵?
Dapper的Execute方法的返回值是什么意思 Dapper Execute返回值详解
如何制作一个表白网站视频,关于勇敢表白的小标题?
*请认真填写需求信息,我们会在24小时内与您取得联系。