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

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.

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

They are helpful. Without die(), script is executed to the end and after that you're redirected.

Imagine script with 20 database queries. Before first query, you have for example

if ($_GET['redirNow']){
   $this->redirect($url);
   die();
}

It won't do any queries. Without die(), it will do all 20 queries.

You're right. It's better to use an error handler and logging mechanism. Take a look at this article:

http://www.phpfreaks.com/blog/or-die-must-die

If the redirection is done using header() then there's a very good reason for using die(). By some programming error, if some data is sent to the browser before the redirect, the redirect will fail. It's better to exit at that stage rather than execute the rest of the script which is not meant to be executed.