3

I checked the opcodes of an application and noticed that the goto command performs the JMP operation. However, some structures such as if, while, and for also use the JMP like goto.

The questions are:
1. Why shouldn’t we use goto?
2. Has the goto command been deprecated in PHP?
3. what's the meaning of Dinosaur in this picture?

enter image description here

Mohsen Movahed
  • 418
  • 5
  • 22
  • Yes, goto is just a jump and so are loops. But this subject has been widely discussed here before. Please check [this question](http://stackoverflow.com/questions/24451/is-it-ever-advantageous-to-use-goto-in-a-language-that-supports-loops-and-func/2809622#2809622) and [this other one](http://stackoverflow.com/questions/46586/goto-still-considered-harmful). And please delete your question (sorry about that, but it will probably be closed anyway). – sidyll May 14 '17 at 19:02
  • 3: this is the punishment for using goto. Alternative to this: being struck by lightning – Marged May 14 '17 at 19:03

1 Answers1

3

In short, goto is plain valid code, it's a matter of taste. BUT, when working with multiple people, code maintainability becomes more important than personal taste. You could fill your code with goto's, but then I'm wondering why you chose an OOP language in favour of pure assembly.

Q1. Why shouldn’t we use goto?

A1. Hard to follow / maintain. Try re-reading your code in a few years.

Q2. Has the goto command been deprecated in PHP?

A2. No.

Q3. what's the meaning of Dinosaur in this picture?

A3. Goto is one of the most ancient control structures of all, which is what the dinosaur is referring to. When you use it, it'll bite you rather sooner than later.

Community
  • 1
  • 1
Code4R7
  • 2,600
  • 1
  • 19
  • 42