PHP header 如果代码为 204,则不显示自定义消息

PHP header not shows custom message if code is 204

我正在写 API,我抛出异常调用一个方法将 header 组合成 return。如果没有内容,我会抛出带有自定义消息和代码 204 的异常。

throw new Exception("my message", 204);

以及构成 header

的方法
if ($status_codes[$code] !== null) {
    $status_string = $code . ' ' . $status_codes[$code];
    header($_SERVER['SERVER_PROTOCOL'] . ' ' . $status_string, true, $code);

    if ($code != 200) die(json_encode(["code" => $code, "message" => $message]));

}

问题是,当我使用代码 204 时,我只显示 204 No content 响应的状态,但没有显示带有代码的消息。我尝试使用代码 400,它显示了自定义消息。

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

RFC 2616

还需要多说吗? :)