Home > Backend Development > PHP Problem > What happens if the php die function does not pass parameters?

What happens if the php die function does not pass parameters?

青灯夜游
Release: 2023-03-15 19:38:02
Original
1776 people have browsed it

php die function directly terminates the execution program without passing parameters and exits the current script. The die() function is used to output a message and exit the current program. It accepts an optional parameter that specifies the message or status number to be written before exiting the script. When the die() function does not pass parameters, you can omit the parentheses after the function and write it as "die;".

What happens if the php die function does not pass parameters?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php die() Function

die() function can output a message and exit the current program.

This function accepts an optional parameter

die(message);
Copy after login

message parameter: Specifies the message or status number to be written before exiting the script; the status number will not be written to the output.

The value of the message parameter can be of string type or int type:

  • If message is of string type, the function will print the string and exit the current Script;

  • If message is of int type, then this value will be used as the exit status code and will not be printed.

    The exit status code ranges from 0 to 254. Note: Do not use the exit status code 255 reserved by PHP. Status code 0 is used to terminate the program successfully.

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
echo &#39;php中文网<br>&#39;;
die(&#39;退出程序,不再向下执行!&#39;);
echo &#39;https://www.php.cn&#39;;
?>
Copy after login

What happens if the php die function does not pass parameters?

If the die function does not pass parameters and the message parameter is omitted, the execution program will be terminated directly and the current script will exit without outputting the message.

Example:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
echo &#39;php中文网<br>&#39;;
die();
echo &#39;https://www.php.cn&#39;;
?>
Copy after login

What happens if the php die function does not pass parameters?

Tip: If the message parameter is empty (omitted), you can omit the following part of the function Parentheses (such as die;).

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
echo &#39;php中文网<br>&#39;;
die;
echo &#39;https://www.php.cn&#39;;
?>
Copy after login

What happens if the php die function does not pass parameters?

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What happens if the php die function does not pass parameters?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template