Search code examples
phplanguage-featuresgoto

GOTO command in PHP?


I've heard rumors that PHP is planning on introducing a "goto" command. What is it supposed to be doing?

I've tried searching a bit, but haven't found anything awfully descriptive. I understand that it won't be a "GOTO 10"-like command...


Solution

  • They are not adding a real GOTO, but extending the BREAK keyword to use static labels. Basically, it will be enhancing the ability to break out of switch nested if statements. Here's the concept example I found:

    <?php
    for ($i = 0; $i < 9; $i++) {
        if (true) {
            break blah;
        }
        echo "not shown";
        blah:
        echo "iteration $i\n";
    }
    ?>
    

    Of course, once the GOTO "rumor" was out, there was nothing to stop some evil guys to propagate an additional COMEFROM joke. Be on your toes.

    See also:

    http://www.php.net/~derick/meeting-notes.html#adding-goto