当前位置:网站首页>PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
2022-07-07 14:07:00 【全栈程序员站长】
die(‘1’) die()和exit()都是中止脚本执行函数;其实exit和die这两个名字指向的是同一个函数,die()是exit()函数的别名。该函数只接受一个参数,可以是一个程序返回的数值或是一个字符串,也可以不输入参数,结果没有返回值。
参考:虽然两者相同,但通常使用中也有细微的选择性。
当传递给exit和die函数的值为0时,意味着提前终止脚本的执行,通常用exit()这个名字。
echo "1111"; exit(0); echo "2222";
当程序出错时,可以给它传递一个字符串,它会原样输出在系统终端上,通常使用die()这个名字。
$fp=fopen("./readme.txt","r") or die("不能打开该文件"); //这种情况下,如果fopen函数被调用返回布尔值false时,die()将立即终止脚本,并马上打印 //传递给它的字符串,“死前还能说一两句话”。
同样的die(‘1’)也通exit(‘1’)一样,输出1
echo "begin"; die('1'); echo "end"; //输出begin1
exit(1) 不输出内容,结束程序
echo "begin"; exit(1); echo "end"; //输出begin
exit(0) 不输出内容,结束程序
echo "begin"; exit(0); echo "end"; //输出begin
exit(‘0’) 输出0 并结束程序
echo "begin"; exit('0'); echo "end"; //输出begin0
exit(‘1’) 输出1 并结束程序
echo "begin"; exit('1'); echo "end"; //输出begin1
return 返回值,后续的程序也不执行,值并不输出
echo "begin"; return 1; echo "end"; //输出begin,return的值没有输出到屏幕,而是返回给了上一层
总结:
return 是返回值
die是遇到错误才停止
exit 是直接停止,并且不运行后续代码, exit ()可以显示内容。
return 就是纯粹的返回值了,但是也不会运行后续代码
exit (0):正常运行程序并退出程序;
exit (1):非正常运行导致退出程序;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113212.html原文链接:https://javaforall.cn
边栏推荐
- leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
- Learn good-looking custom scroll bars in 1 minute
- Three. JS introductory learning notes 15: threejs frame animation module
- 2022第四届中国(济南)国际智慧养老产业展览会,山东老博会
- 谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
- Use moviepy Editor clips videos and intercepts video clips in batches
- The inevitable trend of the intelligent development of ankerui power grid is that microcomputer protection devices are used in power systems
- Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
- A wave of open source notebooks is coming
- 通知Notification使用全解析
猜你喜欢
Postman generate timestamp, future timestamp
模仿企业微信会议室选择
Dotween -- ease function
torch.numel作用
通知Notification使用全解析
航运船公司人工智能AI产品成熟化标准化规模应用,全球港航人工智能/集装箱人工智能领军者CIMC中集飞瞳,打造国际航运智能化标杆
numpy---基础学习笔记
融云斩获 2022 中国信创数字化办公门户卓越产品奖!
持续创作,还得靠它!
Three. JS introductory learning notes 18: how to export JSON files with Blender
随机推荐
神经网络c语言中的指针是怎么回事
Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
如何在shell中实现 backspace
L'application à l'échelle de la normalisation mature des produits ai des compagnies maritimes, cimc, leader mondial de l'intelligence artificielle portuaire et maritime / intelligence artificielle des
nodejs package. JSON version number ^ and~
121. The best time to buy and sell stocks
SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
A wave of open source notebooks is coming
Vite path alias @ configuration
AB package details in unity (super detail, features, packaging, loading, manager)
How to query the data of a certain day, a certain month, and a certain year in MySQL
Three. JS introductory learning notes 10:three JS grid
How to determine whether the checkbox in JS is selected
95. (cesium chapter) cesium dynamic monomer-3d building (building)
航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
融云斩获 2022 中国信创数字化办公门户卓越产品奖!
Logback日志框架第三方jar包 免费获取
Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models
iptables只允许指定ip地址访问指定端口