当前位置:网站首页>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
边栏推荐
- Detailed explanation of unity hot update knowledge points and introduction to common solution principles
- 应用程序和matlab的通信方式
- Laravel 中config的用法
- Three. JS introductory learning notes 10:three JS grid
- 95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
- asyncio 概念和用法
- 过度依赖补助,大客户收款难,冲刺“国产数据库第一股”的达梦后劲有多足?
- Unity的三种单例模式(饿汉,懒汉,MonoBehaviour)
- 用手机在通达信上开户靠谱吗?这样炒股有没有什么安全隐患
- The unity vector rotates at a point
猜你喜欢
Description of vs common shortcut keys
Odoo integrated plausible embedded code monitoring platform
95. (cesium chapter) cesium dynamic monomer-3d building (building)
Eye of depth (VI) -- inverse of matrix (attachment: some ideas of logistic model)
2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
numpy--疫情数据分析案例
通知Notification使用全解析
Shandong old age Expo, 2022 China smart elderly care exhibition, smart elderly care and aging technology exhibition
Application example of infinite list [uigridview]
Unity drawing plug-in = = [support the update of the original atlas]
随机推荐
Simple understanding and application of TS generics
尤雨溪,来了!
航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
Continuous creation depends on it!
Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
如何在shell中实现 backspace
121. The best time to buy and sell stocks
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
Introduction to pyGame games
Enterprise log analysis system elk
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
用手机在通达信上开户靠谱吗?这样炒股有没有什么安全隐患
Three. JS introductory learning notes 00: coordinate system, camera (temporarily understood)
强化实时数据管理,英方软件助力医保平台安全建设
MySQL数据库基本操作-DQL-基本查询
Xcode Revoke certificate
Talk about the cloud deployment of local projects created by SAP IRPA studio
Migration and reprint
Xcode Revoke certificate
Three. JS introductory learning notes 04: external model import - no material obj model