重定向 class 退出()

Redirect class exit()

我有一个关于 OOP 的问题:

我刚开始接触 PHP 中的 OOP。现在我一直在关注教程,在该教程中他们制作了一个 class 用于重定向。

class Redirect {

     public function to($target) {

          header('location '. $target);

     }

}

现在我想知道在 header();

之后是否需要 exit;

发送 Location: header 后使用 exit; 通常是一个好习惯。否则脚本执行不会终止。其余代码将被执行,这在重定向后根本不需要。