Home > Article > Backend Development > What happens if the php die function does not pass parameters?
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;".
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);
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('content-type:text/html;charset=utf-8'); echo 'php中文网<br>'; die('退出程序,不再向下执行!'); echo 'https://www.php.cn'; ?>
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('content-type:text/html;charset=utf-8'); echo 'php中文网<br>'; die(); echo 'https://www.php.cn'; ?>
Tip: If the message parameter is empty (omitted), you can omit the following part of the function Parentheses (such as die;).
<?php header('content-type:text/html;charset=utf-8'); echo 'php中文网<br>'; die; echo 'https://www.php.cn'; ?>
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!