Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: what are the diff between goto and another control structures like while [duplicate]

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

like image 819
Mohsen Movahed Avatar asked Jan 19 '26 13:01

Mohsen Movahed


1 Answers

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.

like image 75
Code4R7 Avatar answered Jan 21 '26 03:01

Code4R7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!