View Full Version : exit; vs. die()

11-22-2010, 12:00 AM
I looked at the difference between these two on php.net, but die() is not quoted at all.

my understanding is that "break;" is only used to break out of small constructs like loops. and that "exit;" terminates the current script but not the page load. and is die() the same as exit;?? I have broken a few of my scripts up because I thought that 'exit' would just break me out of the current "?" tags. if I have two different scripts on the same page, both PHP, does either "die" or "exit" kill both scripts?

11-22-2010, 12:47 AM
yes, exit() & die() are functionally equivalent and when you call either they will stop execution of all PHP scripts in the current scope.

11-22-2010, 12:49 AM
You're probably looking for return

11-22-2010, 02:33 AM
so "return" functions the same way in php that it does in js?

it kills the current script only? as in, the current set of <? tags?? thanks!

11-22-2010, 01:37 PM
The leaves the current script and returns to whatever called it.

11-22-2010, 03:20 PM
it kills the current script only? as in, the current set of <? tags?? thanks!

The current script and the current set of PHP tags aren't necessarily the same. But, what return does is end the current scope. In a function it terminates the function and optionally returns a value. When called in a file, ends execution of the current scope and returns to the file that included it. See the manual (http://php.net/return) page for more information.

11-22-2010, 04:58 PM
THANKS much guys! as always, I appreciate your wisdom!