Php,捕获重定向

Php,捕获重定向,php,redirect,Php,Redirect,所以我有一个代码: function testMe ($redir) { if ($redir) { header ('Location: /'); } } 我想测试这个函数是否使用重定向,但我不知道如何捕获它。这就像抓住了一个例外 编辑:所以我想知道,如果header()没有被编写,但是知道它被调用了你是说你不想有时重定向标题应该总是有效的,你能更清楚地回答你的问题吗?是的,我想“取消”重定向。我明白了。现在我不明白为什么任何代码在header()函数

所以我有一个代码:

function testMe ($redir)
{
    if ($redir)
    {
        header ('Location: /');
    }
}
我想测试这个函数是否使用重定向,但我不知道如何捕获它。这就像抓住了一个例外


编辑:所以我想知道,如果
header()
没有被编写,但是知道它被调用了

你是说你不想有时重定向<代码>标题应该总是有效的,你能更清楚地回答你的问题吗?是的,我想“取消”重定向。我明白了。现在我不明白为什么任何代码在header()函数之后执行…为什么不执行?你没有阻止它。如果将die()放在header()调用之后,则它不会继续。
//calling the function which somewhere does this
header('Location: /');

//testing
foreach (headers_list() as $header) {
    if (strpos($header, 'Location:') !== false) {
        //header location set, function works, removing the set header
        header_remove('Location');
    }
}