search
HomeBackend DevelopmentPHP TutorialDetailed explanation of the goto statement added in PHP5.3

Detailed explanation of the goto statement added in PHP5.3

Jun 25, 2017 pm 01:33 PM
gotophpaboutjoin instatement

In "go" straight out of ASM or any other assembly language. Here's a link: I'd like to know: what can I do to make my code more efficient and how can I work on this larger project without snapping it up. Since goto statements allow you to jump back and forth and accidentally wait in an infinite loop if something happens the wrong way. Can you give me an example of this? EDIT: Well, I've seen the responses on CodeGo.net, and apparently there is widespread concern about "GOTO" and that it is bad. So I've been wondering: why is PHP's troublesome adding it to the language. If they don't see it inside, they won't do it...why? Also: A general comment about "go to" here in the StackOverflow EDIT2: Seeing as this question caused a lot of bad things it made me sad to go and ask my dad about the jump. He is 52 years old and an engineer. He did a good amount of programming in FORTRAN and COBOL during his days, mostly in FORTRAN and COBOL. Now he does IT services, servers and the like. Anyway, he said those things about "back in my day..." After a moment after that, he went back to saying that even back in his days as a student, they were shocked to know that this wasn't A clever idea, but they had no better idea of ​​the situation. TRY/CATCH is still a few years old and Error handling is almost existed. So what are your procedures for checking that you did? Add a few lines at the end that give you the printout and everything you need to check your code, and then you put the lines: "go to print;", or similar, to start the printing of your data. And in this way, you slowly debug your code. He agrees that going into the modern programming world what he finds reasonable is an "emergency interrupt" in debugging and unexpected situations. Sort of like goto fatal_error; and does something for the "is fatal_error" part of your code, showing you the in-depth results. But only if you create the final product there should be no jumps - Late edit: Another way to go about "go" in PHP5.3/PHP6

1. If you are writing good PHP Code , you should not need to jump. I think it's a bug they're adding it in because it just leads to lazy programming. See for a good one on adding this to PHP, and here's Stack Overflow,
2. I've only found out about goto: typing out nested loops. But most new languages ​​have to do this without goto anyway (break in PHP, or break in Java, etc.). Go to the end of a function to clean up the part. But again, this is not in a garbage collected language. In other words, if you don't know whether you goto you shouldn't.
3. Is there such a thing as a jump. Maybe, just maybe, it's possible to get out of multiple nested loops, but you can already do "break 2" like this. Tags in Java also serve this purpose better than go. Maybe it's an exception with code writing when you need to jump to the end of a bunch at a time where one of them fails. But that just fixes crappy code to even crappier code.
4. It can be used for debugging purposes so you don't have to break out or refactor blocks of code just to temporarily change the worker threads.
5. In classic VB coding, using goto is very convenient for simulating try/catch error handling like this:

Function MyFunction() as String
'-- start of error block
'
 On Error Goto Catch
 ' do something here that might cause an error
 MyFunction = "IT WORKED"
 Exit Function
 Catch:
 ' error occured - do something else
 MyFunction = Err.Description
 '
 '-- end of error block
End Function
...这里是一种模拟的try / catch /终于..Function MyFunction() as String
'-- start of error block
'
 On Error Goto Catch
 ' do something here that might cause an error
 MyFunction = "IT WORKED"
 Goto Finally
 Catch:
 ' error occured - do something else
 MyFunction = Err.Description
 Err.Clear
 Finally:
 ' put your finally code here
 '
 '-- end of error block
End Function

It can also be used to clear at the end of a function, although I Thinking you could make another function that could be called to do this in case of cleanup. To be honest, I had never been in PHP and I thought to myself: "Well, I wish there could be a goto. I didn't read up on why they decided to do this, but, those guys are very smart and had the opportunity to consider PHP Very good direction so far, so maybe there's a need for that, we don't know yet.
6. The thing I see about using goto is the cross-language port I wrote in C. The language 's parser Generator generates a parser with goto statements (it's easier to use goto than more sane control structures), and porting it to PHP is now less of a headache ##. #7. When writing finite state machines, you do need one of them when the parsing context is released, although we can live without a jump if
continue $case; is in a switch block. Efficiently jumping to a different situation and closing the scope is achievable in as many languages ​​as there are nowadays. Until then, we were pretty much stuck with goto 8. Jumps can help reduce code duplication in stack unwinding. Pseudocode below:

do A
if (error)
 goto out_a;
do B
if (error)
 goto out_b;
do C
if (error)
 goto out_c;
goto out;
out_c:
undo C
out_b:
undo B:
out_a:
undo A
out:
return ret;

(伪由罗伯特爱,从linux内核归档的邮件列表采取代码:) 
9. 由于之前已经说过,GOTO是唯一真正需要的类型的算法,通常是那些在语言解析或有限状态机。我从来没有错过在PHP缺乏goto语句。 OTOH,我有一个语言,其中只有两个结构是函数和条件goto方法:SNOBOL4。由于意大利面条代码的风险是如此之高,最SNOBOL4是/很小心的避免这一点。但是goto语句也使很紧的编程,创意循环执行等。它实际上是更容易做到的FSM型圈,如果你有在使用goto。 
10. 我承认我转到我的代码。 :) 唯一的理由似乎有利于在最短的flyway从其他语言到PHP(实际上只改变语言不碰控制结构)和重构代码的移植的第2阶段。 我个人认为和同事,因为他们可以避开有条件决裂-S的循环,他们将能够抵御转到诱惑。
11. 生成的代码可以使goto语句,我猜。对生成的代码的好处是,你并不需要去维护它-你只是重新生成它。 
12. goto真正应该尽管这是在语言,并会进行过时由于更好的编程实践。现在添加它似乎是一个倒退的一步。 
13. goto语句中的B大优势就是学习曲线。人们不禁要问,为什么像visualstudia和Mac电脑的工具做的很好。原因是,人们需要的不仅仅是一个伟大的产品,他们希望有一个 伟大的产品,他们可以在短短一个小时左右学习。现在很多 一个天只计划为他们的工作之一。我看到这么多的书说,一个人永远不能 使用goto语句,然后给五年左右的技术,例如,他们说每消除 需要它。我说,只是事实,5是该有多好转到证明 是!!我没有教的五件事,包括异常结构, 把整个章节来解释!!当你真正需要的是一个简单的跳转 可在30秒内进行解释。当然,你可以创建恶意代码与他们如果 希望---但是,嘿,最不想写糟糕的代码,如果他们 他们才可以呢。最goto语句在我们的实验室所做的代码简单 了解和学习;程度远远超过了读一本2000页的书。

The above is the detailed content of Detailed explanation of the goto statement added in PHP5.3. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment