There is a discussion on the PHP Internals list about adding a GOTO statement to PHP (via NuCleuZ).
A little History … (lest we forget)
Gotos have had a long and sordid history in computer science. In the early days, before languages had a rich set of control structures, goto’s were it. It turned out that overusing GOTOs made the control flow of programs hard to follow and thus programs difficult to maintain. Dijkstra’s 1968 paper Go To Statement Considered Harmful is considered a classic for recognizing this fact. GOTO enriched programs are sometimes called Spaghetti Code
A movement was spawned to eschew the GOTO with as much zealotry as todays modern Object Oriented fanatic uses to eschew “procedural code.” This movement was called Structured Programming. The central premise being that any given block of code should have one entry point and one exit point. Presto … control flow is now easy to understand.
And so the structured programmers waged war on low level control structures in favor of high level control structures. And you know what? They won. Languages were constructed without GOTO statements. Computer science degrees became harder to get for those with an affinity to goto. Higher level control structures flourished.
As some of the zealotry faded, it turned out that sometimes multiple exit points can be useful for clarifying code. Continue, return, and break and later throw all provide ways to provide multiple exit points to a block of code.
Multiple entry points remain blissfully rare except for the occasional confusing fall-through case in a switch statement.
Early in my career, I had the (mis)fortune to be a maintenance programmer on some older programs written in the unstructured style with gotos. This is where I learned debugging, code smells and refactoring. Not having a source code control system, the programmer before me was loathe to actually remove unused code from a program, so he would simply GOTO around it. After years of this, a program might be 50% dead code. Goto “patches” were used instead of subroutines. A goto would jump to a distant location, perform some operations, and then jump back. FOR loops were simulated with gotos. Living with wholesale GOTO abuse, like some sort of war atrocity is not easily forgotten.
GOTOs in PHP
What surprised me most about the GOTO patch for PHP is the positive reception that it has received. There seem to be three arguemnts in favor of it:
- it is useful for error handling.
- it is useful for writing parsers
- it can be faster than other control structures
Regarding error handling, I think that using GOTO for error handling is like simulating for loops with GOTO. Why use the low level concept, when the higher level concept works better? try..catch and try..finally are designed for error handling. Use them.
Would people try to simulate gotos with exceptions? Perhaps. While that might be bad, gotos might be worse. The big difference is that exceptions can only provide multiple points of exit from a block of code. Gotos can provide multiple points of entry. Goto is far easier to abuse than exceptions.
Another difference between gotos and exceptions is that gotos in PHP are limited to a single scope, while exceptions can cross scope. This is important when a low level function may know that an error has occurred, but not what to do about it.
Using gotos for error handling increases the active area of variables involved in the error from the point of error occurrence to the point of error handling. This is bad and not just for compiler register allocation algorithms.
I think that people who want to use goto for error handling probably don’t understand how to use exceptions properly yet. (Thinking in C?)
Gotos are handy for parsing? Yes, but they are usually used in generated code built by lex or yacc. This is code not meant to be maintained by humans. If you are hand constructing a parser, you probably aren’t going to use tight state transition loops as generated by these programs. It is possible to write a reasonably fast parser in PHP without goto.
Goto is faster? This is related to parsing. The cost of parsing in PHP is allocating memory for substrings, anyway. This will probably dwarf any gains in control flow. If you sacrifice maintainability for speed at the micro level, you obfuscate opportunities for real performance gains, which almost always occur at the macro level. Don’t sacrifice speed for maintainability.
Having a goto statement makes control flow analysis more difficult for any current or future optimizing compilers. What is confusing for people turns out to be confusing for computers as well.
Java provides a little used labeled statement which can be the target of a break or continue statement. This allows escaping deep nesting (a bad code smell on its own) without introducing the problems of multiple points of entry. This might be a better alternative.
Not once in four years of programming in PHP have I thought to myself “I wish PHP had a goto statement.”
Perhaps worst of all, I think having goto will cause serious programmers to take PHP less seriously as a language.
You are right, goto’s can be abused. But that does not mean that mean that it cannot be used to make code more clean. I do like using goto’s for error handling and I don’t like using exceptions. Why would PHP be better for disallowing one particular style?
I think that the language should not force programmers to (over)user one particular feature. My personal belif is that the way Java uses exceptions is nightmarish. I didn’t like the way Pascal forced us single exit point in its procedures/functions. Goto in PHP will only add to the flexibility of the language and the fact that that flexibilty can be abused should not deter us from getting it.
Regarding your response to perceived arguments in favor of GOTOs, what you fail to answer is how an increased feature set takes away from the language or makes it less usable. Will PHP be taken less seriously? Perhaps, but… frankly… who cares? Languages don’t exist to be cool and get invited to the popular syntax’s table. A programming language is a tool, not a badge of leethood.
But back to the arguments you listed in favor of GOTOs, why did you leave out #4) “Readability and Maintainability”. Some may find multi-entrancy inscrutable, but they have probably never developed in assembly.
I think that PHP is a very incoherent language. Adding support for ‘goto’ when it seems like PHP is finally trying to focus on adanced OO model just seems strange. I agree with Jeff: I’ve never once missed goto in PHP. While I’m sure it’s true that ‘goto’ can be used correctly, I think that there’s a lot of merit in having a coherent language. Whether you (dis)like the way Java (or C#, etc.) does things, it can certainly be said that Java is a coherent, consistent, etc. As a developer I find internal language coherence a very attractive quality in a programming language.
“Goto is far easier to abuse than exceptions” – You actually mean, Goto is far easier to write code in a style that I don’t like than exceptions”.
“Don’t sacrifice speed for maintainability.” – Except where speed is more important than maintainability.
“Not once in four years of programming in PHP have I thought to myself ‘I wish PHP had a goto statement.’” – That is more a statement about you than the usefulness of gotos.
It was a little scary that you said, “Perhaps worst of all, I think having goto will cause serious programmers to take PHP less seriously as a language.” Who exactly are these “serious programmers?” Aren’t they the Ada, C++, Java crowd that you yourself complain about because they use their elitism to support high hourly rates?
I am no fan of gotos. My prejudice comes from the same sources as yours. But I have seen expert programmers refactor long functions with very deep logic into code that was much easier to understand and maintain.
I also think that, in PHP5, gotos could be a reasonable alternative to exceptions or return value and ifs in certain situations. Especially to improve performance and simplify logic.
Do you really want to outlaw sharp tools because amateur builders can hurt themselves? A better analogy is to think of goto as a stick of dynamite. It’s not something to use very often, but if you come across a big rock it better than building an around it, no matter how elegant the workaround is.
Hi.
I cannot believe they would even consider adding GOTO into the language. Dumb. Really really dumb. Why select a broken misfeature right when PHP is finally starting to get it’s internals sorted out? It was pointless enough adding the “final” keyword.
Python and Ruby have blazed the OO trail for simplifying languages so as to make them more powerful and elegant. It’s happened before. Niklaus Wirth gave a classic lecture describing Oberon. He put up a slide showing the features that had been added to Modula 2 to make Oberon so much more powerful. There were four. He then put a up a slide showing the features removed from Oberon. There were thirty one.
You only have to look at Perl to see what happens when the kitchen sink mentality collides with a programming language.
yours, Marcus
Sara, the problem is that eventually, I will end up having to maintain some PHP that someone else wrote using GOTOs. I don’t want to do that. Also, I have programmed in assembly, but much prefer not to. Multiple entry points are very confusing. Most modern languages avoid the goto, or if they have it or something similar, it is heavily restricted as to which blocks of code you can enter. (as is the goto of C#) There are cases where gotos can improve clarity and maintainability, but if you take away error handling (where exceptions are better), then these cases are few and far between.
CT, I’ve been programming for 22 years. I took my first full time paying programming job in 1987. I’ve written, read and maintained alot of code in that time. This is one area where I know what I am talking about. I am not a programming style pluralist. The style I like is better and I can (and do) explain why.
I am sympathetic to the argument that break n is hard to understand and would have no problem with a break label or a continue label capability in PHP, as described in the Java as above.
Everything else can be done with existing constructs. The fact that PHP has reached version 5.0 without goto is proof of that. PHP is not Perl. There does not have to be a zillion ways to do any one thing.
The performance issue is a red herring. Don’t automatically assume that goto is faster. Virtual machines don’t have the same performance characteristics of CPUs.
Tim Bray describes three programming baskets: the scripting tribe, the OO factory, and the close-to-the-metal gang. Goto is a construct for the close-to-the-metal-gang, but PHP is not a close-to-the-metal language, nor should it be.
Jeff, I’ve been programming longer than you and have also seen lots of code. And I imagine that my actual position on using goto is generally the same as yours. I am just more open to the posibility of using goto than you (I may be wrong about your openness to goto).
I think my main point is that we should be open to all potential tools, even if they have fallen out of favor, because we may find new, beneficial ways to use them.
The Structured Programming and OO movements have had very positive effects on the programming world, but neither is the perfect solution. Neither solves every problem better that the other. The fact that we program structured and OO intermingled is testament to our flexability and that together they solve problems better than either independently.
As for existing constructs, it’s not whether a thing CAN be programmed with existing structures, but if something else might work better in some situations. You can code anything using only if and goto. PHP got to 5.0 with out exceptions is only proof we solved problems without them. There does not have to be a zillion ways to do any one thing. But, there does not have to be only one way either. I think two and sometimes three ways is a good balance.
I don’t think the performance issue is a red herring. Performance issues are always part of the equation and when it is important good programmers lose their structured/OO religion fast and document well. That’s not to say that there is often a more elegant solution that meets the performance target.
What I didn’t hear from the various comments about adding goto was anyone saying, “Hey let me think about some of my current patterns and apply goto to them and see if I come up with something interesting or maybe even better!” Instead I heard either “goto sucks” or “if someone else want is and it doesn’t affect me, go ahead.”
CT, I don’t know anything about you, I didn’t mean to aim my “I’ve been programming a long time” rant specifically at you.
I did mean to say that the longer I program, the less pluralist I become. I almost combined the last two replies into a main post, but decided against it, which is why I took so long to reply.
I am open to the possibility that goto could be better in some situations. Its just that nobody who is arguing for it has produced any concrete examples where it would be better. The examples that have been produced so far are highly speculative. I cannot be convinced in this case with with a hypothetical. I have seen the non-hypothetical abuse of goto. I need to see some real world code that performs a real task (no do_something() functions) that would turn out better with goto than with an alternative such as a while, exceptions, or break n, or even break label. Not to mention refactored with less deep nesting.
Regarding performance, if I understand correctly, the goto that was submitted requires a hash lookup and has to keep track of a table of labels. This is overhead that may make the goto compare unfavorably performance wise with other solutions. It remains to be seen if goto in php is faster than alternative methods.
Jeff, I in my “I’ve been programming a long time as well” for the same reason you did, just to clarify. I don’t add emoticons, I just type, so if my comments seem brusque they are not meant that way in the least. I read and comment to learn, and I would not read you blog if I wasn’t open to learning a thing or two.
I think that some concrete examples have been given and I would quote a programmer you know who said, “Following my API Design principles, I think the smallest amount of code wins.” I think that can apply to goto as well. I also think that minimal commenting can deal with your multiple points of entry concern. From my quick look at the patch I doubt the hash lookup is any worse than a switch statement.
If you read what I have written, all I have ever said was that goto could possibly be useful and we should be open to that possiblity. That a pretty middle-of-the-road statement and I was just a little suprised how conservative most of the comments around the web have been.
PHP Feature Request
I want PHP to support… #ifdef … #endif preprocessor directives! Why? Good question, let me explain my thinking… I write a fair bit of de…
With people requesting goto: statements for PHP, I thought it time I revealed the feature I’m wishing for
I tend to ageee that there is not much difference between:
#ifdef DEBUG
and
if (defined(’DEBUG’))
However, I think I get a sense of what this guy is looking for. It seems like there should be a way to keep debug and comments seperate from the the production code for releases, but keep them together during development. Not quite compiling, but like it.
Imagine having separate files named .php and .phpmeta (for metadata like Debug & Documentation). When editing, the .php and .phpmeta files are combined. If you turn Debug ON the debug code is included in the .php release files or omitted if Debug is OFF. Documentation is always stripped. Something like the Mac’s resource fork as a place to put meta data, comments, debug code, test code, etc.
I don’t think there is any practical way to do this. I could be in the editor, a build tool, in a PHP cache addon, etc. But if there were some standards it might catch on.
You know who used goto statements to good effect? Dijkstra. In fact, he used two of them when he showed how you could implement semaphores simply in C. I believe one of them could have been replaced by a multi-level break, but the other one could not be.
Similarly, gotos can be very useful if you want to implement, say, function calls for an interpreter. There are some Scheme interpreters written in Java that suffer from the Java language’s deliberate lack of a(n implemented) goto statement.
So I’d have to agree with CT here, because the fact of the matter is, goto can *still* do things that other control statements can’t do–unless you have full continuations–and even if you did, goto generally does its job with less overhead, and in a straightforward manner. Of course, use goto sparingly–if you never have to use it, that’s fine. But don’t come whining to me when the day comes when you *do* end up having to use it, or when it would vastly simplify your task at hand.
gotos are jmp assembly instructions. you can’t live without it. if you dont wanna use, dont. but leave it quietly there you mother fucker because we, real programmers, are going to use it because we know how. stop whinning and go program.
I personally think the goto statement is very usefull. Not for your day to day programming (never used goto in this situation) but for code generators. E.g. It is much easier to implement a state machine generator with goto’s than with control structures.
PHP is not a low-level programming language. If you want performance use C. I thing that if implementing goto in PHP is hard it should not be.
>>Not once in four years of programming in PHP have I thought to myself “I wish PHP had a goto statement.”
well, all people here have their prespective about “goto”,
i think that it is right not to fell secure using it in our programs but also is a programming feature, maybe bad, but a feature from the very past of computing, and i say:
what if we use some old-fashioned damned feature to have a chance to solve a problem of today?
Can i use the label-goto feature to build an aspect-oriented add-on languange based on php?
I want to investigate this prespective.
So leave ‘goto’ in peace and optionally use it!
Alexiou Bill
try/catch is often LESS clear than goto. Instead of always jumping to a specific location, you’re often leaping into the wild blue yonder, whatever implicitly defined location was set before. You can even throw out of nested calls, which blows my mind — that kind of goto is illegal, but anything goes with try/catch.
But it’s Not Goto, Therefore It’s Better.
I’ve seen try/catch heavily abused in languages like java. Imagine a set of functions and methods with no return values — everything either silently works or throws an error of some sort. To figure out which of 9 functions is throwing an error, you could need individual try/catch blocks for each one!
Something ate my reply.
How is try/catch any better than goto? You might be jumping ANYWHERE with try/catch, whereas goto at least goes to a defined label. Even goto won’t let you leap out of nested statements, but anything goes with try/catch…
This concept has been abused in languages such as java, also. Imagine a complex set of functions with no return values — if anything happens they just throw some sort of message. Individual try/catch blocks are needed for each to tell which threw what message!
“George Bush”: i agree with ya.. on the asm instruction. I”ve been there from asm to OO and know the ups and downs of goto’s. Still after 100+ php projects i never missed it upto today hehe.. i need a quick patching of an state-machine in php and the goto would save me a bundle of euro’s (today that is as next week the restructuring might bite me in the but).
My opinion.. goto’s are required in the set but not required in each project or situation.
Gr.
*Bump*
“George Bush” nice style. Nice intelligent approach at a topic… well done! I bet that makes you a top coder!
Jeff, i agree with you to some extents. GOTO’s are for lazy bastards who cant be fucked to find another way of doing it. It’s like i see people ‘break’ing out of loops all the time, yet another style of coding i find irritating. Yes, use it if there isn’t a more logical approach, but usually there is. My code is proof of that.
And those of you who are dissing PHP because you just scraped through your C++ degree.. Get a job!
I’ve been using PHP for almost 5 years now, and I have to say that I really wisth there was GOTO in the basic function set. It’s far more pleasant to maintain assembly-like code then go through a dozen of classes that programmer before me wrote to simply connect to MySQL. But the classes were added there, right? So GOTO should be, too.
I have been a software developer/engineer/architect since 1978, and aside from some code written in Basic (UGH) during the first 2 years, I have NEVER seen a need to use GOTOs. I’ve written everything imaginable from operating systems, middleware, applications, and embedded systems in C, C++, Forth, Java, Perl, Python, and have also dabbled a bit in Lisp.
As far as deeply nested loops, those are better broken out into subroutine calls that are easier to understand and maintain. I have rarely seen a need for use of a “break n” statement.
Some may claim it’s “elitism”, but I say it’s just a matter of coherent style. I have been in many debates over GOTO, and no one have been able to show me convincing evidence that GOTOs are needed. Ever. And I’ve seen some major abuses of the use of GOTOs in C — such as a looping constructs where “while” or “do” or “for” should’ve been used. Needless to say, that code was unmaintainable, and this was for a major multimedia product for a major computer company that is now defunct. You’ve heard of them. They used to produce the Amiga, recall…
Mark me as a bigot, but I’ll say this: most of the use of GOTOs I’ve seen in my career was the result of poor coding style and practices. Rarely have I ever seen them used wisely or in a case there was no better approach.
Forgive my pre-posting… The PREVIEW did not show the use of (code) and (/code), as it says it does…
Trying this…
Please feel free to delete this post, just not the one that follows…
Just another rant:
I have coded now for 42 Years. In that time I have used all the major languages. (C, C++, Fortran, Cobal, Pascal, Ada etc. and now PHP). My great love was assembler for all different types of uP’s. I probable wrote the spaghetti code that somebody mentioned earlier.
You know what? it doesn’t make a bit of difference if you have a GOTO or not. It just depends on how good the programmer is and if he has enough time in the project to make it maintainable for the next guy!
PHP is a nice easy language that most people can use. Most of the code I have seen is pretty bad BUT it works! so if a GOTO makes somebodys life a little easier put it in! The coding snobs dont have to use it if they dont want to!
Is it just me or do the bulk of the arguments here seem defined by ones religous underpinnings. LOL!
I personally agree with and appreciate what CT has to say on this topic:
If it is possible to add GOTO statement without a change in interpretter performance it’s ok with me.
But if we r takin PHP as OOP becomin language, there is no need for GOTO statement.
Thou this is my first time .. when I thought bout GOTO in PHP, only for makin some tests and omit some code, so i don’t realy think I would need it
.
[...] goto” in the address bar (my new favorite way of searching recklessly) which led me to goto in PHP which linked to [PHP-DEV] GOTO operator (a 2004 discussion) and eventually a message from Andrey [...]
I have been programming in PHP for about six years now. I came on this page because I googled for php goto. Why? Because I need it for the first time in 6 years, but HELL, do I need it! Yes goto’s are generally a bad idea, but just sometimes, in exceptional and rare cases, they are just *exactly* what you need and all workarounds make your code so much harder to read (using while loops, flags, and so on).
[...] calls, witch unfortunatelly can’t be used in PHP. You can read more about goto in PHP on this blog. But with some breaks and some minor modifications, I got over it fast. You can download the class [...]
I agree with the prior poster.
goto are a requirement of modern languages. There are times where it simplifies logic instead of having some insane while/if loops statements. goto were clearly abused in the past (I have been an assembly programmer for years, I remember those branching hells), but I have also seen some code with outrageous if/while statements where a goto would have brought a clean way to resolve the algo.
I think that trouble creeps in when you have to use multiple goto statements within the same file. The golden rule is to use gotos only within a function. Outside of that best practice, it becomes very dangerous.
A person mentioned earlier that Java/C# are better. yadi yada. C# supports the goto statement, so I don’t know where that person was going with it.
The issue seems to be good coding practice rather than whether goto serves any useful purpose.
I think we try to approach PHP from more of a Object oriented look and move away from procedurals methods. If serious developer are to consider PHP as enterprise level language, this language needs to move towards satisfying the professionals then being the language of the choice for high school kids.
PHP6 will see great changes. With more emphasis on object oriented concepts, design patters and more versatile library like java, PHP will start to enter the enterprise level and that’s where I want to see PHP go.
Here’s a snippet of code. having GOTO:
A:
————————————–
for ($a=1; $a
There is nothing wrong with a GOTO in structure programming, PROVIDED that the target labels cannot be outside of a procedure/function body. It was BASIC and FORTRAN that gave GOTO a bad name. Now I would love to have GOTO in PHP.
There’s a demand for a GOTO statement. I have yet to see that this come from people who were unaware of all the other structures. But sometimes a GOTO is just the fastest and easiest, and it can make code clearer.
Here’s code running through a 2-dim array, looking for an Anna.
$had_it = true;
for ($i=0, $i
OK, code didn’t reproduce in this forum.
“I think we try to approach PHP from more of a Object oriented look and move away from procedurals methods. ”
“OO” and “procedural” are not in contrast.
PHP should have a goto command! I had to work around using while and switch and that makes it nearly unreadable
Two things: Pendulums and Generations
1. The further a pendulum swings one way the greater the tendency to swing back.
2. As newer generations rise the further they get from the lessons learned by the previous generations and the more they question the old wisdom.
You can see it in everything from the trend towards mysticism, conspiracy theories and religion and the slow death of scientific rationality through to the evolution of programming languages.
Thus there will forever be such discussions as this.
The banishment of GOTO and the creation of the first Object were both Eureka moments – and despite the pendulum and the generations – the Darwinian forces that cause balance between coding speed, maintainability, economics etc will bring about the inevitable final death of GOTO.
I’ve been coding PHP since 2000. Today was the first time I thought “a goto statement would really be good right now”
Main thing I’m doing right now is:
if ($error) {
print "error message";
goto FOOTER;
}
# do useful stuff here
FOOTER;
include("./graphicdesign/footer.inc");
Now I have to include the:
#do useful stuff here in an else block which makes it hard to read the code.
I agree with most people in so far as “Why add goto?”. I remember using goto in the MOST strict linear / procedural code in the 1980’s. It was fun. It worked. It was necessary.
When you think about the goals and ideas that drive OOP (with out getting too addicted to the application of OOP because it is abused) goto is a step backwards.
Although my experience is lower than others on this post, I have believed that PHP is quickly going down a path I am not interested in traveling. Goto is, to me, an affirmation that they are NOT listening to the real needs and desires of the community. Addressing the lamers and complainers is what usually ruins a perfectly good MMO. I see little difference. Anyone with a brain will quickly move away from PHP rather than inject a well formulated opinion into the PHP binary collective.
I am transitioning to Python personally. Most of the developers I know are doing the same. PHP is where they will make money fixing other people’s problems, but ultimately they will write in Python, dotNET, Java, etc.
[...] think having goto will cause serious programmers to take PHP less seriously as a language.” – Jeff Moore, July 29th 2004 Possibly related posts: (automatically generated)Aptana PHP Eclipse: The [...]
High Level codes already known ideas. And it works up until it just does not work anymore. When you need something new, you need Low Level control, you need GOTO. Else you may find yourself trying lines and lines and lines of code that just does not quite make it, and fails, but the solution is just one simple GOTO command that does perfectly in so few lines of code.
/* I put this one GOTO here because ... */[...] over some comments on goto use, one of the concerns I find most interesting is that of the kitchen sink mentality. Personally, I [...]
I’ve been using PHP for several months now, and it’s been enough of a struggle that I’ve started to look for other alternatives. The one I’ve liked the most so far is Haskell.
Haskell doesn’t have GOTO statements. Nor does it have for or while loops (you are strictly limited to recursion). Nor can you change a variable once you have assigned it a value.
Nonetheless, you can do wonderful things in Haskell! Indeed, by getting rid of variables, it becomes a lot easier to debug programs, because functions generally don’t have “side effects” that do weird things, like unexpected changing of global variables.
If only it didn’t take so long to get used to the syntax…
First, Let me agree that most programmers should avoid goto like the plague. They’ll almost always screw things up using it.
Having said that, there is *one* good reason for adding goto, and that is for compilers that target PHP. For example, a good functional language like Haskell does things like tail-recursion optimization. Now in trivial cases, you can translate tail-recursion into a simple while loop, but in cases where you’re dealing with mutually recursive functions, a while loop doesn’t cut it.
Good article and good quality. I want to outline the end of the article:
My respect for PHP is going down and down. I thoguth it is a joke, but in PHP 5.3 there is goto. This is a clear sign of the low quality of the PHP community, especially compared to Java, Python, Ruby, Groovy etc.
Spaghetti coder now are using classes and objects, but their mentality is still the same. How needs a goto statement? Spaghetti coders. The easyness of PHP permits to everyone to use it and there are some drawbacks from this.
While the other languages has a clear syntax, a well estblished error management, real OOP capabilities, PHP has a different error management for different functions, not overloading/polymorphism…
The goto in PHP is a clear sign of the wrong mantality of the PHP community sites.
This confirms that I will use a different language in the future.
@Riccardo Tacconi
‘I thoguth it is a joke’
thoguth
‘This is a clear sign of the low quality of the PHP community’
It’s reflects on the “community” poorly?
‘Spaghetti coder now are using classes and objects’
Grammar.
‘How needs a goto statement?’
Who’s how?
‘easyness’
is that like peasyness?
‘permits to everyone’
lol
‘languages has’
grammar
‘estblished’
Taking abbreviations a little too seriously…
‘The goto in PHP is a clear sign of the wrong mantality of the PHP community sites.’
This sounds familiar!
Okay, I’m done >>
@jistanidiot
are you serious???
you can’t think that really this goto is better to read than an else…
if this is your example, where you really need goto, than its ridiculous…
if ($error) {
print "error message";
goto FOOTER;
}
# do useful stuff here
FOOTER;
include("./graphicdesign/footer.inc");
vs.
if ($error) {
print "error message";
}
else {
# do useful stuff here
}
include("./graphicdesign/footer.inc");
I would really like to see a example with sence…
- Listen, I am done in this building. How do I get to the restaurant?
- Leave this room, you’ll see a step, step one floor down. If you were doing something in that room just end it, leave the room, go one floor down. If you were doing something there, end it and go one floor down. In that room you had asked somebody a question, receive the answer even if you don’t need it anymore, now step one down again. You are now on the ground floor. Go straight forward. You will be asked if you want to turn right or left. Turn right, then go straight ahead. Now you are now at the restaurant! Enjoy.
- Thanks. But, eh, out of this window I can see a big sign where it says “Restaurant”. It is there?
- Yes!
- Why didn’t you point and just tell me to go to there?
- No, we use structured language here. “Go to” is unprofessional and can so easily lead to confusion! You have walked to where you are in a structured way. Now you must leave in the same way.
- Really? I wish you could have made an exception in my case.
- Ah, an EXCEPTION! But did you TRY something? If so I will throw an exception, and if you have set up a CATCH, you will save a lot of time.
- So, I should go back an set up a TRY. Is that more structured?
- Far more. That is the pro way of doing it!
- But I am in a hurry. I will simply take the elevator down, and go to the restaurant.
- It’s just so wrong. Nobody can have respect for that. Please Sir, do yourself a favor. Leave this room, you’ll see a step, step one floor down. If you were doing something in that room…
use goto by allmeans BUT variable functions in PHP are a lot cleaner and more powerful:
consider example:
first_block(); //runs first_block and then GOTO to default blank_function if($condition_is_met
first_block(”second_block”); //runs first_block and then GOTO to second_block if($condition_is_met
third_block(”first_block”); //runs first_block and then GOTO to second_block if($condition_is_met)
function first_block($exitfunction=”blank_function”){
if($condition_is_met){$exitfunction();}
}
function second_block($exitfunction=”blank_fucntion”){
if($condition_is_met){$exitfunction();}
}
function third_block($exitfunction=”blank_fucntion”){
if($condition_is_met){$exitfunction();}
}
function blank_function{return true;}
I found myself regurgitating what you said in your 1 and 2 points while answering the three questions. =) I’ll be brief instead
Ah, GOTO that brings back memories. Overall, great points, keep it up!
WOW, over six years old and still coming up in searches!
I guess I am retarded, but the idea of a simple goto compared to an else close bracket 4000 lines down, just seems alot easier, and cleaner.
Funny, 6 years later and 2 days apart, I find myself here echoing Dan. When working with old code and suddenly you have a condition for which you’d like to skip a huge block of code it’d be nice to use goto(’label’); or however the construct is written, instead of wrapping the whole block
if(new condition){do it}else{
………………………………………………….a couple pages of code
}
p.s.
The form here asks for my website. I broke it the other day and havn’t bothered to fix it. It ain’t pretty!
goto is and has always been awesome. anyone criticising it is clearly a moron. why would goto not be well received?
`,, I am very thankful to this topic because it really gives great information ~;;
There is a full sub-market inside of the area of the cellular telephone industry place linked to the jailbreak or unlocking of the mobile phones so that they can be utilized on any mobile network, and latest Supreme Court selections in the USA handed down have confirmed that the jailbreak sector is legal and genuine. That is, conclude-user clients are really inside their legal rights to do what they wish to their cellular cellphone handset to enable the cell phone to function on other network carriers which is normally known as jailbreak or unlocking the network block.
Learn how to Jailbreak your iPhone
how to be able to unlock your cellular phone
I really enjoy reading your site since it includes very interesting matters.
hee, thank you for your good article about Six Flags. I think it is the greatest thing in the world. Leave me a comment. And again many thanks for your good article….
[...]goto in PHP – Professional PHP[...]…
brinca brinca…
[...]goto in PHP – Professional PHP[...]…
uggs…
[...]goto in PHP – Professional PHP[...]…
I’m looking for more information about online computer science degree…
[...]goto in PHP – Professional PHP[...]…
snow ugg boots…
[...]goto in PHP – Professional PHP[...]…
Okay, nice to see a useful blogs. Thanks for the information.
301 Moved Permanently I was suggested this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my problem. You’re incredible! Thanks! your article about 301 Moved PermanentlyBest Regards Justin
Thanks , I have just been searching for info about this subject for a while and yours is the best I’ve discovered till now. But, what about the conclusion? Are you positive concerning the supply?