Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: exit; vs. die()

  1. #1
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts

    exit; vs. die()

    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?

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    yes, exit() & die() are functionally equivalent and when you call either they will stop execution of all PHP scripts in the current scope.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    You're probably looking for return
    Dave .... HostMonster for all of your hosting needs

  • #4
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    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!

  • #5
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    The leaves the current script and returns to whatever called it.
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    ajetrumpet (11-22-2010)

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by ajetrumpet View Post
    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 page for more information.

  • Users who have thanked Inigoesdr for this post:

    ajetrumpet (11-22-2010)

  • #7
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    THANKS much guys! as always, I appreciate your wisdom!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •