Tag Archives: die()

What’s the difference between die() and exit() in PHP?

Knowledge map advanced must read: read how large-scale map data efficient storage and retrieval>>>

What is the difference between die() and exit() functions in PHP

I think the two have the same function, but I wonder if there are some differences between the two… What is this


#1st floor

As mentioned earlier, the two commands produce the same parser token

But

One small difference is how long it takes for the parser to return the token

I haven’t studied the PHP parser yet, but if it’s a long string of functions that start with “d” and a short string of functions that start with “e”, it’s going to take some time to find the function name of the function that starts with “.” e “. There may be other differences due to the way the entire function name is checked

I doubt it will be measurable unless you have a “perfect” environment dedicated to parsing PHP and many requests with different parameters. But there must be a difference. After all, PHP is an interpretive language


#2nd floor

There’s no difference – they’re the same

PHP Exit Manual:

Note: this language construction is equivalent to die()

PHP die Manual:

This language construction is equivalent to exit()


#3rd floor

They are essentially the same, although there are other suggestions in this paper


#4th floor

They sound similar, but exit () also allows you to set the exit code for the PHP script

Usually, you don’t actually need this script, but when writing a console PHP script, you may need to check with bash that the script does everything in the right way

You can then use exit () and capture later. Die() is not supported

Die() always exists as code 0. So essentially, the die() command does the following:

<?php
echo "I am going to die";
exit(0);
?>

Same as the following:

<?php
die("I am going to die");
?>

#5th floor

Mold in PHP manual:

Die – equivalent to exit

You can even die and exit same - with or without brackets

The only advantage of choosing die() instead of exit() may be that it saves time typing extra letters; -)