【发布时间】:2022-01-25 13:35:22
【问题描述】:
当我在我的管理员中单击注销时,此错误会出现在我的日志中。 我不明白什么是弃用的 php 8.0.14 谢谢你的帮助
我的功能
public static function redirect(?string $url, ?string $http_response_code = null)
{
if ((strstr($url, "\n") === false) && (strstr($url, "\r") === false)) {
if (str_contains($url, '&')) {
$url = str_replace('&', '&', $url);
}
header('Location: ' . $url, true, $http_response_code);
}
exit;
}
错误
[25-Dec-2021 15:32:00 UTC] PHP Deprecated: header(): Passing null to parameter #3 ($response_code) of type int is deprecated in /home/www/test/includes/OM/HTTP.php on line 63
[25-Dec-2021 15:32:00 UTC] PHP Stack trace:
[25-Dec-2021 15:32:00 UTC] PHP 1. {main}() /home/www/test/admin/login.php:0
[25-Dec-2021 15:32:00 UTC] PHP 2. OM\OM::redirect() /home/www/test/admin/test.php:133
[25-Dec-2021 15:32:00 UTC] PHP 3. OM\HTTP::redirect($url = 'http://localhost/test/admin/index.php', $http_response_code = *uninitialized*) /home/www/test/includes/OM/::OM.php:329
[25-Dec-2021 15:32:00 UTC] PHP 4. header($header = 'Location: http://localhost/test/admin/index.php', $replace = TRUE, $response_code = NULL) /home/www/test/includes/OM/HTTP.php:63
[25-Dec-2021 15:32:12 UTC] PHP Deprecated: header(): Passing null to parameter #3 ($response_code) of type int is deprecated in /home/www/test/includes/admin/OM/HTTP.php on line 63
[25-Dec-2021 15:32:12 UTC] PHP Stack trace:
[25-Dec-2021 15:32:12 UTC] PHP 1. {main}() /home/www/test/admin/login.php:0
[25-Dec-2021 15:32:12 UTC] PHP 2. OM\OM::redirect('index.php', '') /home/www/test/admin/login.php:100
[25-Dec-2021 15:32:12 UTC] PHP 3. OM\HTTP::redirect($url = 'http://localhost/admin/admin/index.php', $http_response_code = *uninitialized*) /home/www/test/includes/OM/OM.php:329
[25-Dec-2021 15:32:12 UTC] PHP 4. header($header = 'Location: http://localhost/test/admin/index.php', $replace = TRUE, $response_code = NULL) /home/www/test/includes/OM/HTTP.php:63
【问题讨论】:
-
不推荐将
null作为响应代码参数传递的行为——正如错误消息所说的那样