ID: 29287 Updated by: [EMAIL PROTECTED] Reported By: abodeman at yahoo dot com -Status: Wont fix +Status: Open Bug Type: Feature/Change Request Operating System: Irrelevant PHP Version: Irrelevant New Comment:
It's still likely to be added ;-) Previous Comments: ------------------------------------------------------------------------ [2004-07-26 19:44:54] jhelzer at cse dot unl dot edu Whether this is the relevant place or not, to treat goto and labels as two heads of the same body (as you seem to imply) is silly. I can understand a reluctance to implement goto, but adding labels for the break statement make a tremendous amount of sense. ------------------------------------------------------------------------ [2004-07-21 00:00:59] jhelzer at cse dot unl dot edu I am curious, why not? ------------------------------------------------------------------------ [2004-07-20 22:31:59] [EMAIL PROTECTED] We won't implement goto and or labels. ------------------------------------------------------------------------ [2004-07-20 21:58:09] abodeman at yahoo dot com Description: ------------ As I have outlined in the PHP manual in user comments under "break", the "break n" syntax is obnoxious. Code containing a "break n" can silently become broken if it is surrounded by another loop; I believe it is the only language feature that will break this way. It is also difficult to figure out where control resumes after a "break n"; you have to count loops and switch statements, but ignore if statements. With this in mind, I propose a much better syntax, one that has been time-tested and proven to work well in other languages: line labels. By adding line labels to PHP, you can say "break label;" and break out of the loop or switch statement labeled as "label". Putting more loops in the code won't break anything, and it is easier to determine where control will resume. While you're at it, a "goto" statement would also be very much appreciated in PHP. Yes, I know, the vast majority of programmers are yelling at me now, because they have been inundated by books and teachers telling them that goto is always 100% evil. The truth of the matter is that goto is sometimes the natural way to do things. Sure, it's possible to write code without goto, but it's also possible to write code without switch statements or for loops. And eliminating goto from a language does not automatically make well-written code. Consider the following scenario: There is an if statement inside a for loop inside a switch statement inside two while loops. The situation is not uncommon. Now, inside this if statement are some 60 lines of code. The fifth line of code is some test; if the test fails, execution should jump just past the end of the if statement, inside the for loop. Currently the only way to do that is to wrap the remaining 55 lines of code inside yet *another* if statement, adding yet *another* level of indenting. Ick. Obviously the natural solution here is to have a goto statement that jumps to where it needs to go. But PHP doesn't have anything that will work. There's not even a good kludge for it. If you didn't want to wrap the 55 lines in an if statement, you could wrap the 60 lines in a do { ... } while (0); and just use a break, but that's even worse. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29287&edit=1