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 4 of 4

Thread: Should I Exit?

  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,073
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Should I Exit?

    Should I add an exit() statement to each of my case statements?

    PHP Code:
    // Determine Sort-Type.
        
    switch ($sortRequest){
          case 
    "by-date":
            
    header("Location: " BASE_URL "/some_path");
            break; 
    If so, where exactly?

    Sincerely,


    Debbie

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    410
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Short answer: Between header(); and break;

    However:
    It depends on the rest of the code and what exactly you want it to do. If you want it to simply stop what it's doing and redirect to that location, add exit() between header() and break;. If you want other stuff to happen after the switch then don't do anything. If the switch is the last thing to happen, you don't need it to use exit() because it will end after that anyways.

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    additional note: if each of your cases does a redirect, you may also call exit() after the switch().
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #4
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,073
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    additional note: if each of your cases does a redirect, you may also call exit() after the switch().
    Okay, thanks for the help guys!!

    Sincerely,


    Debbie


  •  

    Posting Permissions

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