调用一个函数并阻止被调用的函数在PHP中执行重定向


Call a function and prevent the called function from performing a redirect in PHP

我正在调用一个函数,该函数在最后执行重定向。我可以阻止我调用的函数以某种方式执行重定向吗?

function a() {
    // here i would want to prevent the redirect. but i must call b always
    b();
    return 'a';
}
//function that i can't modify. It always redirects.
function b() {
    header("Location: http://google.com", true, 200 );
}
$return = a();
echo $return;
// expected output: 'a' not a redirect to google

如果你问为什么,我不想修改函数b(),因为它是一个库函数。

调用库函数后,尝试使用

header_remove("Location")

http://php.net/manual/en/function.header-remove.php

希望那个头球还没有发出。。。

header_remove(在设置了标头之后)怎么样?

http://php.net/manual/en/function.header-remove.php