在PHP函数中返回语句之后的代码 [英] Code after a return statement in a PHP function

查看:118
本文介绍了在PHP函数中返回语句之后的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和一个非常陈旧的网站一起工作,我不会把我的名字写进去。在现有代码中似乎有一个重复发生的模式,如下所示:



pre $函数foo(){
$ a ='a';
$ b ='b';

return;

$ c ='c';
$ d ='d';
}

我很努力地从一个函数中删除现有的代码,写,并且一切都按原样运作。但我想知道为什么?



我学到的所有东西(除goto行调用外)都告诉我return语句后面的代码是无用的。是吗?为什么前面的程序员会这样做?

解决方案

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?

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?

解决方案

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

这篇关于在PHP函数中返回语句之后的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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