dotkpay Posted June 23, 2011 Share Posted June 23, 2011 Hello, I just started using the new feature of php 5 "goto" that skips a bunch of code to a labeled point. But how reliable is goto. I was advised by a programmer to avoid it. Should this be the case? My concern is about its reliability because I currently use it very often in my new projects. Can it cause any form errors in files? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/240228-reliability-of-goto/ Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 The problem with 'goto' is that it leads to spaghetti code - code that jumps from place to place, all layered and threaded with other such code. This makes the code hard to read, hard to edit, and hard to debug. Using 'goto' is a clear indication of bad design, and generally doing things wrong. Well formed code does not use 'goto'. Quote Link to comment https://forums.phpfreaks.com/topic/240228-reliability-of-goto/#findComment-1233963 Share on other sites More sharing options...
dotkpay Posted June 23, 2011 Author Share Posted June 23, 2011 Is there an alternative to "goto", how else can I skip code? Quote Link to comment https://forums.phpfreaks.com/topic/240228-reliability-of-goto/#findComment-1233973 Share on other sites More sharing options...
AbraCadaver Posted June 23, 2011 Share Posted June 23, 2011 Is there an alternative to "goto", how else can I skip code? What do you mean "skip code"? If you don't need to execute it then don't put it there. If you may sometimes need to execute it based on a condition, then use an IF or SWITCH with that condition. Or you can conditionally call a function that contains that code. For virtually any example you post, we can give you a better way than goto I'm sure. Quote Link to comment https://forums.phpfreaks.com/topic/240228-reliability-of-goto/#findComment-1233979 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.