PHP和要在PHP 5.3中添加的goto语句 [英] PHP and the goto statement to be added in PHP 5.3

查看:116
本文介绍了PHP和要在PHP 5.3中添加的goto语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"goto"语句直接来自ASM或任何其他汇编语言.

这里是链接: http://be2.php.net /manual/en/control-structures.goto.php

我想知道:这能使我的代码井井有条吗?我如何在较大的项目中实现这一目标而又不搞砸. 由于goto可以让您来回跳动,因此如果使用错误的方式,意外的赋值和无限循环将等待发生.

有人可以给我一个很好使用此方法的例子吗?

好的,我已经看到了一些答复,并且显然对于"goto"语句的使用存在广泛的共识,而且很糟糕.

所以我仍然想知道:为什么PHP会费心将其添加到语言中.如果他们看不到其中的内容,就不会这样做...那为什么呢?

也:在此处有关StackOverflow的一般性讨论"goto"

由于这个问题引发了很多关于goto声明的不幸,我去问了我父亲.他今年52岁,是一名工业工程师.
他告诉我有几次他在自己的时代做了很多编程工作,大部分时间是在FORTRAN和COBOL中进行的.如今,他从事IT服务,服务器和网络管理等工作.

无论如何,他说了一些有关回到我的日子..."
在讨论了一下之后,他回到了goto声明,说即使在他还是学生的时候,他们都已经知道使用它不是一个聪明的主意,但是那时他们并没有更好的选择.尝试/捕获仍然需要数年的时间,几乎不存在错误处理的问题.
那么,您做了什么检查程序?在末尾添加几行,以便打印输出以及所有需要检入代码的内容,然后放置以下行:"goto printing;"或类似的东西,开始打印数据. /p>

通过这种方式,您逐渐调试了代码.

他同意在现代编程世界中使用goto毫无用处.他认为合理的唯一用途是紧急中断",用于极端调试和意外情况. Kinda很像goto fatal_error;,并且在代码中具有致命错误"部分,可以做一些事情来向您展示更深入的结果.
但是仅在创建某些内容的过程中.成品不应具有goto语句.

最新关于PHP5.3/PHP6中"goto"的另一讨论

解决方案

如果要编写好的PHP代码,则无需使用goto.我认为他们添加它是一个错误,因为这只会导致懒惰的编程.

请参见

http://www.procata. com/blog/archives/2004/07/29/goto-in-php/

对于在PHP上添加此功能以及在此处出现堆栈溢出的情况进行了很好的评论

GOTO仍然被认为是有害的吗?

The "goto" statement comes straight out of ASM or any other assembler language.

Here's a link: http://be2.php.net/manual/en/control-structures.goto.php

I'm wondering: what can this do to make my code more well-organized? How can I implement this in larger projects, without screwing it up. Since the goto will allow you to jump back and forth, accidental assignments and infinite loops are waiting to happen if you use this the wrong way.

Can someone give me an example of a good use of this?

EDIT: allright, I've seen some of the replies and apparently a wide consensus exists about the use of the "goto" statement and it being bad.

So I'm still wondering: why would PHP bother to add it to the language. If they didn't see something in it, they wouldn't do it... so why?

Also: A discussion here on StackOverflow about "goto" in general

EDIT2: Seeing as this question induced a lot of bad things to be sad about the goto statement, I went and asked my father. He's 52 years old and is an Industrial Engineer.
He told me a couple of times he did a good amount of programming in his days and mostly in FORTRAN and COBOL. Nowadays he does IT services, server&networkmanagment and such.

Anyways, he said some stuff about "back in my day..."
After discussing that a bit, he came back to the goto statement, saying that even back in his days as a student, they allready knew it wasn't a smart idea to use it, but they didn't have much better back then. Try/catch was still years away and error handling hardly excisted.
So what did you do to check your program? Add a few lines at the end that allow you to print output and everything you need to check in your code, and then you place the line: "goto printing;", or something like that, to start the printing of your data.

And in this manner, you gradually debugged your code.

He agrees that the use of goto in the modern programming world is pretty useless. The only use he finds justified is an "emergency break", to be used in extreme debugging and unexpected situations. Kinda like goto fatal_error;, and have the "fatal_error" part of your code do some things to show you in-depth results.
But only during the creation of something. A finished product should not have goto-statements.

LATE EDIT: Another discussion about "goto" in PHP5.3/PHP6

解决方案

If you're writing good PHP code, you shouldn't need to use goto. I think it's a mistake that they're adding it in, as it just leads to lazy programming.

See

http://www.procata.com/blog/archives/2004/07/29/goto-in-php/

For a good commentary on the addition of this to PHP, and also, here on stack overflow,

GOTO still considered harmful?

这篇关于PHP和要在PHP 5.3中添加的goto语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆