头函数在PHP中与exit不工作


header function not working with exit in PHP

我在另一个函数内部有一个header函数,但问题是它不能与退出一起工作,即使它没有退出也可以正常工作。如果没有exit,它会重定向到test2.php,但是如果有exit,它根本不会重定向。

<?php
function goTo($string){
header("Location:".$string);
exit;
}
goTo("test2.php")
?>

工作版本:

<?php
function UrlGo($string){
header("Location: $string");
exit;
};
UrlGo("http://google.com")
?>