
PHP introduces "goto" - zain
http://www.php.net/manual/en/control-structures.goto.php
======
dflock
The first user contributed note on that page:

    
    
      <?php
        wtf:
        echo 'For real!?';
        echo 'Srsly!?';
        goto wtf;
      ?>
    

Heh.

------
jdp
Why is everyone jumping on this as a negative? Goto isn't inherently evil. Of
course in most cases there is a construct that would be a better fit than
goto, but it does have its uses. As far as readability goes, odds are a
programmer isn't going to be jumping to a label 300 lines up, its used mostly
to break out of nested loops and to simulate stuff like state machines. Check
out <http://david.tribble.com/text/goto.html>

~~~
pygy
They already have a break statement to get out of loops of arbitrary depth.
<http://www.php.net/manual/en/control-structures.break.php>

And why, except perhaps for the hack value, would you simulate a state machine
in PHP?

GOTOs are good when used wisely in certain contexts. I don't see where they
could be of any use in the PHP niche (but I'd be glad to hear about such
examples). Seasoned PHP coders don't need it.

Besides, PHP is mostly a beginner's programming language, who learn by example
using code found online. They will be exposed to even worse practices from day
one.

------
noodle
ugh. they caved. too bad. this kind of hurts their movement towards OO. now
we'll probably see see tons of people using goto as bandaid measures instead
of learning better techniques to solve their problems. look out for raptors.

~~~
huhtenberg
Oh, common. Are we talking about the language that allows run-time _renaming_
of the variables ? I mean if you have _that_ then adding a goto hardly
qualifies as "too bad".

~~~
wvenable
How exactly do you rename a variable?

~~~
jrockway
I suppose he means something like:

    
    
        $foo = 42;
        $bar = 69;
        $which_one = 'foo';
        print eval "\$$which_one";

~~~
huhtenberg
Actually, no. That's not it. This is an equivalent of a pointer to a variable
in C.

What I was referring to is the actual renaming the variables in run-time, i.e.
change variables' key in the table of variables. So the code like this:

    
    
      for ($i = 0; $i < 8; $i++)
      {
        ..
        <rename i to j>
        ..
      }
    

would throw a run-time error on the second iteration, because $i will become
undefined. It was completely and utterly "out there", that's why I remembered
it. Also showed it to a bunch of people, all of them were equally amazed. But
now I can't seem to find where I saw it and what the exact syntax was.

~~~
randallsquared
I don't know how you'd do that in PHP, but I'm pretty sure that you can do it
fairly easily in Python and Lua, and I've never heard anyone claim that (more
or less) first class environments are a feature of bad languages.

~~~
huhtenberg
You are missing the point. PHP is a very odd and subjectively inconsistent
mixture of language features, so adding a goto support is hardly a _bad
design_ decision.

------
sil3ntmac
Sweet! Hope they implement COMEFROM next.

<http://en.wikipedia.org/wiki/COMEFROM>

~~~
mynameishere
Most langauges have that. It's called "catch".

------
abyssknight
I feel like I've been trolled by the PHP haters again.

All of this language-ism is killing my chi.

~~~
abyssknight
I feel this is a relevant cross post, at least for my own amusement:

<http://news.ycombinator.com/item?id=650328>

------
nir
So what? If you think goto is harmful, don't use it. If you think PHP in
general is harmful, don't use that either. Maybe help build something
comparable to Wordpress or Drupal in your favorite language so other people
can use it instead of PHP. If all you have to offer is empty sarcasm, goto
Reddit.

~~~
tetha
And then you have to maintain spaghetti code in PHP with gotos.

------
raffi
I've thought of adding goto to Sleep. Have you ever looked at the code in the
Linux kernel? It's full of gotos. They use goto's to make sure functions have
one exit point and to cleanly deal with errors in one spot.

~~~
paulgb
Kernel hackers know presumably what they're doing and use goto only when they
have a good reason. Can the same be said of PHP programmers?

I'm all for the "don't protect programmers from themselves" philosophy, until
I'm the guy who has to use or maintain the code.

~~~
ars
Not having goto's is not going to help you in the slightest from bad
programmers.

~~~
zach
I disagree. Goto is the Comic Sans of keywords, a tool which may be used
tastefully but ends up far more commonly abused to horrible effect.

------
ars
Yay! Finally I've been waiting for this for a long time.

I can finally get rid of some spaghetti code: goto emulation via while loops.

Yes, it's not often you need goto, but sometimes you do.

~~~
pbiggar
No way! I do exactly this. Switch statement, while loop, and lots of continue
statements.

Its a lowering of basic blocks that I want to print out to test.

What's yours?

------
apgwoz
Finally! Now PHP really is the web's assembly language.

------
patryn20
So....all the progress PHP has made in recent years has not been
undone.....but has been rendered irrelevant. Never again will anyone be taken
seriously while using PHP. It will once again be purely the domain of amateurs
and script kiddies.

This is being said as someone who has created marvelous applications in PHP
and has dealt with all the PHP language shortcomings up to this point. Makes
me truly, truly sad.

------
robotron
This isn't some kind of surprise. It has been discussed for some time now.

There is also no reason for a developer to use it if it's not wanted.

------
sev
I understand why C and C++ have goto statements (as well as other older
languages). But to actually "introduce" goto's in a language that didn't have
it or need it, making it even possible to write such horrible code is, in my
opinion, pointless and worthless. It promotes illegible and bad code in
general.

------
antirez
Goto is a good idea in C, not only for the obvious low-levelness reasons, but
also because if you can write C you are almost certainly a bit wiser than the
average PHP programmer that may use goto for things I prefer don't think about
before to go to sleep :)

~~~
uriel
"If you want to go somewhere, goto is the best way to get there" \-- Ken
Thompson

------
ahlatimer
I was working for a company doing mostly COBOL programming about a year ago,
and I can honestly say that GOTO can be used neatly and effectively, but it
can also turn code into a horrible mess. For COBOL, it's an absolute must.
There are no while or for loops in COBOL (at least not in the version we were
using), so you had to replicate that with GOTO's and paragraphs. For PHP, I
really don't see this as necessary.

So long as it's not widely publicized in tutorials and the like, I don't
really see a whole lot of novice coders getting their hands on this. I'm not
particularly concerned about experienced programmers using GOTO in PHP,
especially if they've used in another language where it is more necessary.

------
tamersalama
Anyone knows where's the PHP core team blog/site (if there's such team)?

~~~
tamersalama
Someone pointed out the minutes-of-meeting
<http://www.php.net/~derick/meeting-notes.html#adding-goto>

------
drawkbox
This helps quite a bit... It helps people move on from PHP because it is the
'language that later added goto'. A sad day for programmers in PHP.

gotos are a bad programmer's recursive method. Even people that use while
loops like pepper scare me a bit. I have seen many'a'app get stuck in memory
draining death loops with goto and even while(). Flags are dead, long live
events and messages.

------
e4m
I once used that a lot on my C64. Made sense back in 1982 and in limited
cases, makes sense today.

------
look_lookatme
From the page:

"It is not allowed to jump into a loop or switch statement. A fatal error is
issued in such cases."

At least that isn't possible. What a mess it would be if this wasn't the case.

------
travisjeffery
Haha, wow how sad. The kind of sadness created when realizing how disgustingly
pathetic our evolution can often be.

I can't wait to spend minutes of my life when I have to go through another
programmer's PHP code who uses gotos.

~~~
encoderer
I think you left out your _goto CalmDownFirst_ line in your
_DramaQueenPreventor_ class.

------
jnorthrop
This feels like a giant step towards the past.

~~~
kaiuhl
Using PHP is a giant step towards the past.

PHP will never fully be utilized as an OO language by the vast majority of its
user base due to its syntactically terrible standard library and history as a
functional language.

As such, this addition makes plenty of sense.

~~~
ars
PHP will never fully be utilized as an OO language because it's a stupid idea
to write web pages with an OO language.

Web pages are just not suited to OO. Encapsulation can be done via functions -
adding OO to it gets you nothing except longer code.

Making things more complicated does not make them better.

~~~
randallsquared
I almost agree with this. I'm experimenting with Kohana for my latest code,
and even though this is supposed to be the lean, fast OO framework, there's a
LOT of boilerplate associated. Less than a third of my code is actually get-
things-done code, as opposed to more than two thirds last time I was using a
home-grown, not-especially-OO framework.

Maybe some other framework does this better, though.

