Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/240228-reliability-of-goto/
Share on other sites

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'.

Link to comment
https://forums.phpfreaks.com/topic/240228-reliability-of-goto/#findComment-1233963
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/240228-reliability-of-goto/#findComment-1233979
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.