Die() Equivalent To Echo Error & Exit() ?

sunny_pro

New member
Joined
Jun 18, 2017
Messages
86
Points
0
Php Folks,

Reading this link, did I understand correctly that you use exit() to halt the script and die() to halt the script after spitting out an error mssg on screen ?

https://stackoverflow.com/questions/1795025/what-are-the-differences-in-die-and-exit-in-php

So, the following 1 is equivalent to 2 ?

1.
PHP:
if(!1==2) {
echo "no match";
exit;
}
2.
PHP:
if(!1==2) die("no match");
Latter seems shortest if you want to halt the script after giving an error. And so, best to use that. Right ?
And, if you don't want to give error then just use like this. Right ?

PHP:
if(!1==2) {
exit;
}
The above were rush rough examples.
 

Rob Whisonant

Moderator
Joined
May 24, 2016
Messages
2,489
Points
113
Never really looked at the difference of die and exit. Personally I have always used them this way.

exit - when I exit a script prematurely for a a reason that was not an internal error. Like when a page was called and not all POST variables have been sent.

die - when something went terribly wrong. Like a connection to a mysql database failed.
 

sunny_pro

New member
Joined
Jun 18, 2017
Messages
86
Points
0
yes die() and echo error then exit() both gives the same result.

in die function after validating condition as per the given parameter die() is triggered which explicitly stops the process. and in exit function we prints the definiteness error message and exites from the run-time program.
You said things the wrong way round. Lol! Double check what you said.
 
Older threads
Replies
4
Views
1,865
Replies
5
Views
4,826
Replies
1
Views
4,529

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top