1

So I am using the following style of code if(array_key_exists('some_value', $_POST)){echo 'hi';}

For PHP 5.2.17 I am getting a warning from this style of code. This is the warning: WARNING: argument 2 for array_key_exists() is not either an array or an object on line: 123

This seems strange to me because I believe that the $_POST array should always be defined. Is that not the case? I'm not sure what would cause the $_POST array to not be considered an array. I am not resetting $_POST to anything so it should exist as an array at all times. Does anyone have any idea what is wrong. Please let me know if more information is needed and thank you for the help.

Edit: I should note that this only happens on the production server. My local environment does not have this problem.

4

2 回答 2

2

改为使用if(isset($_POST['some_value'])) { echo 'hi'; }。从来没有遇到过问题。

还要检查您是否没有覆盖或取消设置$_POST (或者您正在使用的某些框架正在为您执行此操作)。我避免使用超全局变量这样做,因为我认为这是一种不好的做法,并且可能会像这样让人头疼。

于 2013-04-22T16:16:16.077 回答
2

和仅在脚本被编入或传出时才被填充。在您的示例中,您收到该错误的原因是脚本没有发布操作。在检查某个帖子值之前,您应该检查以确保有帖子:Superglobals $_POST$_GETPOSTGET

if(isset($_POST)) {
    //The form was posted
}

以那种方式。从那里,您可以使用 来检查某些值array_key_exist,或者您可以进一步检查isset($_POST['myKey'])

于 2013-04-22T16:20:32.557 回答