...

View Full Version : exit; vs. die()



ajetrumpet
11-21-2010, 11:00 PM
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?

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

djm0219
11-21-2010, 11:49 PM
You're probably looking for return

ajetrumpet
11-22-2010, 01: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!

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

Inigoesdr
11-22-2010, 02: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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum