【发布时间】:2014-08-10 20:59:28
【问题描述】:
为什么此行在我的实时服务器中返回 null?
filter_input(INPUT_SERVER, 'REQUEST_METHOD');
直播服务器是php5.5.9
我错过了什么吗?
我以为是用来代替下面的全局方法的?
$_SERVER['REQUEST_METHOD'];
一些代码,
public function __construct()
{
// Construct other generic data.
$this->clientRequestMethod = filter_input(INPUT_GET, 'method'); // such as list, add, update, etc
$this->clientPostMethod = filter_input(INPUT_POST, 'method'); // such as update
$this->serverRequestMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD'); //such as get or post
}
public function processEntry()
{
// Determine the $_SERVER['REQUEST_METHOD'] whether it is post or get.
if ($this->serverRequestMethod === 'POST' && $this->clientPostMethod != null)
{
$this->processPost();
}
else if($this->serverRequestMethod === 'GET' && $this->clientRequestMethod != null)
{
$this->processRequest();
}
}
【问题讨论】:
-
如果你不应用过滤器,为什么要使用
filter_input()? -
Doc says 它返回“
NULLif the [...] variable is not set”,另见this comment -
他已经将变量名设置为
'REQUEST_METHOD',并且过滤是可选的,所以我也很好奇为什么这不起作用 -
@birdspider 如果我使用
$_SERVER['REQUEST_METHOD']而不是filter_input(INPUT_SERVER, 'REQUEST_METHOD'),我会得到数据 -
这可能是一个长期存在的 php 错误bugs.php.net/bug.php?id=49184 - 无法找到已修复的参考
标签: php filter-input