我使用这个编码标准包来检查我的代码:https ://github.com/inpsyde/php-coding-standards
但是每当我运行 php 时,我都会收到以下错误:
13 | WARNING | Detected access of super global var $_SERVER, probably needs manual inspection.
| | (WordPress.VIP.SuperGlobalInputUsage.AccessDetected)
14 | WARNING | Detected access of super global var $_SERVER, probably needs manual inspection.
| | (WordPress.VIP.SuperGlobalInputUsage.AccessDetected)
14 | ERROR | Missing wp_unslash() before sanitization. (WordPress.VIP.ValidatedSanitizedInput.MissingUnslash)
这是课程:
<?php declare(strict_types=1);
namespace Dummy;
class Dummy
{
public function __construct()
{
$this->route();
}
public function route(): string
{
if (isset($_SERVER['REQUEST_URI'])) {
$request = esc_url_raw($_SERVER['REQUEST_URI']);
if ($request === "/users") {
return PLUGIN_PATH . '/src/page/UserPage.php';
}
}
return "";
}
}
有没有办法使用 $_SERVER 而不会收到这些警告?
对于 wp_unslash(),我不删除斜杠,有没有办法在不抑制错误的情况下纠正这个问题?
提前致谢。