PHP goto statment?

Discussion in 'PHP' started by jaguarx, Sep 14, 2009.

  1. #1
    I thought PHP 4 and 5 don't support the goto statement. But I found www.us3.php.net has a description on it. Which way is true?
     
    jaguarx, Sep 14, 2009 IP
  2. Deus Ex

    Deus Ex Peon

    Messages:
    531
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Both support goto statements but it is just considered inefficient
     
    Deus Ex, Sep 14, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you read the page completely, goto is a new statement since PHP 5.3 - it won't work in earlier versions.
     
    premiumscripts, Sep 14, 2009 IP
  4. digitaltrader

    digitaltrader Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #4
    Why would you need a goto statement?
     
    digitaltrader, Sep 15, 2009 IP
  5. jj20051

    jj20051 Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I can tell you why:

    Simply put your working on some code and you decide you need to see how something would run by skipping over a section of code. Before php 5.3 you had to cut the data out, save it and test it. Now you can just add 2 lines to your code (very short lines at that) and save your self a butt load of work. There are also applications in the while loop that it would be nice to have a jump out feature from one while loop to another section of code.
     
    jj20051, Sep 15, 2009 IP
  6. digitaltrader

    digitaltrader Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #6
    fair enough, I usually just comment out sections or put a $temptag with an if statement (ie if $temptag =true{}else{}) I can see how a goto tag could be useful for testing to save time
     
    digitaltrader, Sep 15, 2009 IP
  7. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #7
    Adding a multi-line comment is two lines.
    Even smaller than goto lines.

    I've thought of things goto would be nice for from time to time, but I always find a reason why it would make it harder in the long run down the road to use the goto. It's like using duct tape to patch an innertube in a bike tire instead of just replacing the tube.
     
    joebert, Sep 15, 2009 IP
  8. jj20051

    jj20051 Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hey duct tape works really well. Don't dodge it until you've had to use it...

    Anyway your probably right, but they are still trying to make php better so don't shoot them because their newest features aren't the "world's greatest." I'd rather they keep making php better and more advanced than drop it like hypervm.
     
    jj20051, Sep 15, 2009 IP
  9. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #9
    Don't use goto, ever! There are much more efficient ways to do things.
     
    crath, Sep 15, 2009 IP
  10. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #10
    I live next door to a bike shop. I've seen bike tubes with pieces of string tied around holes.
     
    joebert, Sep 16, 2009 IP