PHP 函数中的 return 语句后的代码
我正在使用/在一个非常过时的网站上工作,我不会把我的名字放在上面.现有代码中似乎有一种重新出现的模式,大致如下:
I'm working with/on an extremely antiquated site that I wouldn't put my name to. There seems to a re-occuring pattern in the existing code, along the lines of:
function foo() {
$a = 'a';
$b = 'b';
return;
$c = 'c';
$d = 'd';
}
我非常不愿意从我没有编写的函数中删除现有代码,并且一切都按原样运行.但我想知道为什么?
I'm very relunctant to delete existing code from a function that I didn't write, and everything is working as is. But I would like to know why?
我所学到的一切(除了 goto 行调用)都告诉我 return 语句后面的代码是无用的.是吗?为什么以前的程序员会这样做?
Everything I ever learnt (with the exception of a goto line call) tells me that the code following the return statement is useless. Is it? Why would the previous programmer do this?
推荐答案
return
语句之后的代码永远不会被执行.很可能最初的开发人员想快速测试变量的其他值,并将他的旧实验留在函数中.使用版本控制,您可以删除现有代码并恢复它以防您再次需要它
that code after the return
statement will never be executed. most probably the original developer wanted to quickly test other values for the variables and left his old experiments in the function. use version control and you can delete existing code and recover it in case you ever need it again
相关文章