duanbixia7738 2011-08-24 13:40
浏览 34
已采纳

重定向还是死? 这些死亡陈述有用吗?

Inherited a Cakephp application which uses a great deal of $this->redirect($url) statements; all of them are followed by die(); as follows:

$this->redirect($url);
die();

I can only assume this is some poor form of error trapping, but I can't see why this would ever be necessary. $this->redirect uses a URL redirect function from my framework, nothing our application has altered; if it doesn't work then my framework doesn't work, so nothing on the whole site would work in the first place. The die(); statements make it very hard to weed through the code and find where errors were expected (they're not using exceptions of course).

Is there any reason to keep these? The only functionality I can imagine they provide is to prevent execution of logic beyond a redirect in a function that wasn't supposed to execute, but it looks like bad unnecessary coding to me.

  • 写回答

4条回答 默认 最新

  • duanbai5348 2011-08-24 13:53
    关注

    You can read the source . function redirect($url, $status = null, $exit = true) the $exit is default true and @param boolean $exit If true, exit() will be called after the redirect

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含