当前位置:网站首页>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
边栏推荐
- 讲师征集令 | Apache SeaTunnel(Incubating) Meetup 分享嘉宾火热招募中!
- [wechat applet] Chapter (5): basic API interface of wechat applet
- Eye of depth (VI) -- inverse of matrix (attachment: some ideas of logistic model)
- 通知Notification使用全解析
- 分类模型评价标准(performance measure)
- Iptables only allows the specified IP address to access the specified port
- [excelexport], Excel to Lua, JSON, XML development tool
- Regular expression string
- Introduction to pyGame games
- 深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
猜你喜欢
Unity3d click events added to 3D objects in the scene
Three. JS introductory learning notes 10:three JS grid
C4D learning notes 2- animation - timeline and time function
Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
How does geojson data merge the boundaries of regions?
通知Notification使用全解析
Plate - forme de surveillance par étapes zabbix
Description of vs common shortcut keys
MySQL数据库基本操作-DQL-基本查询
Unity drawing plug-in = = [support the update of the original atlas]
随机推荐
[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
Eye of depth (VI) -- inverse of matrix (attachment: some ideas of logistic model)
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
Eye of depth (VII) -- Elementary Transformation of matrix (attachment: explanation of some mathematical models)
Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
121. The best time to buy and sell stocks
Three. JS introductory learning notes 03: perspective projection camera
修改配置文件后tidb无法启动
AE learning 01: AE complete project summary
如何在shell中实现 backspace
【花雕体验】15 尝试搭建Beetle ESP32 C3之Arduino开发环境
2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
Performance comparison of tidb for PostgreSQL and yugabytedb on sysbench
分步式监控平台zabbix
SPI master RX time out interrupt
A JS script can be directly put into the browser to perform operations
The unity vector rotates at a point
Continuous creation depends on it!