59 points · by zain · 17y ago · 87 comments
<?php
wtf:
echo 'For real!?';
echo 'Srsly!?';
goto wtf;
?>
Heh.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.
But for PHP, which is mostly for web development, I would think using exceptions is a much peer-friendlier way of handling what you'd probably be using goto for in a web app.
If you're writing state machines or parsers, PHP probably isn't the way to go anyway. But hey - whatever floats your boat.
Adding goto just incremented the keyword count, nothing more. Bad coders will still keep on writing bad code, with or without the help of goto.
So I doubt this will make PHP any worse than it already is. They should really consider adding some useful features, though.
$foo = 42;
$bar = 69;
$which_one = 'foo';
print eval "\$$which_one";All of this language-ism is killing my chi.
Error handling and portability of code from other languages will make PHP more widely used. That is the goal of the founders/contributors: make PHP used as widely as possible on it's features alone.
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.
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.
Its a lowering of basic blocks that I want to print out to test.
What's yours?
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.
There is also no reason for a developer to use it if it's not wanted.
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.
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.
"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.
I can't wait to spend minutes of my life when I have to go through another programmer's PHP code who uses gotos.
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.
I can assure you that PHP is not a functional language (despite all my efforts to make it one).
2) php is procedural, not functional. (edit: whoops, beaten to this punch)
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.
Maybe some other framework does this better, though.
Welcome to 1980.