开发者

PHP - exit or die() in AJAX requests?

开发者 https://www.devze.com 2023-02-03 01:49 出处:网络
What\'s the best practice here? Using d开发者_JAVA技巧ie() or exit()? What\'s the difference between the two?

What's the best practice here? Using d开发者_JAVA技巧ie() or exit()? What's the difference between the two?

if($_GET['do_thing']):
  echo 'bla bla';
  exit(); // or die(), or something else?
endif;


die('bla bla');, echo 'bla bla';exit(); and exit('bla bla'); do the same thing. Personally, I use die only for debugging code, and an empty exit for regular termination - as in your case. However, die and exit are synonyms, so it does not matter which one you use.


I use die() when making mysql queries to log the errors, I use exit to bail out of loops.


I prefer die, but for no particular reason. PHP Docs say that exit is the real language construct (http://www.php.net/manual/en/function.exit.php) and die is simply an alias, but both work. It just depends on your coding style and choice of grammar!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号