Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do you have a favorite 'exit'? Why?
#1
PHP Code:
<?php
//exit program normally
exit;
exit();
exit(
0);

//exit with an error code
exit(1);
exit(
0376); //octal
?>
~source

Is there any difference between these two 'exit;' vs. 'exit();'
I'm guessing no difference, but curious to know...
Why would anyone bother to use 'exit();' if 'exit;' does the same thing? Toungue
Do you have a favorite 'exit'? Why?

#
MyBB is the best forum software! Exclamation

Reply
#2
exit is a language construct. It makes no difference if you use exit or exit() it just depends on the developer.

Personally I use exit but other developers might like to be consistent and use exit() along side exit('Some message').

exit is also an alias of die (I tend to use die when outputting error messages and use exit when I want the script to generally exit)
Reply
#3
I usually just use die() but sometimes exit; Smile
Reply
#4
I prefer "exit;"

Though, you shouldn't rely too much on that, it's better to do :

PHP Code:
<?php
if($var == "something")
{
//do something
}
else
{
//do something else
}
?>

Then :

PHP Code:
<?php
if($var == "something")
{
//do something
exit;
}
//do something else
?>
(08-10-2014, 08:05 PM)Omar G. Wrote:  1.8 has this feature, if you want to wait.
Reply
#5
Personally, unless there's some kind of exceptional situation, I just let execution run off the end and return normally. Of course, almost all of the PHP I've written was for MyBB so exit() would mess things up, but even in normal C/C++ programs I just return from main to end the program.
[Image: LogoO.png]
Reply
#6
I use exit(), which is for consistency as Nathan stated. I use exit(); for exiting and die("Some Message"); for error messaging... but I often use:
echo "<pre>";print_r($array_var);die("</pre>");
for debugging insertions too Toungue
Reply
#7
I use exit(); myself...not sure why I just always preferred that to just exit;.

I do of course use die() too but in terms of just exit options I like exit();.
Reply
#8
BTW, Would..
//exit with an error code (for example)
exit(123);
...by default, log the error in the Apache logs (assuming you normally see PHP errors there) or do you need to add the instruction to log?

EDIT:
Checked here and didn't see much use of the error code.

<off topic>
Quote:Don't use the exit() function in the auto prepend file with fastcgi (linux/bsd os).
It has the effect of leaving opened files with for result at least a nice "Too many open files ..." error.
</off topic>


EDIT #2
Just tested and don't see it in the Apache log.
How do you ever use that error code?, since the script has stopped... Toungue
#
MyBB is the best forum software! Exclamation

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)