duanping2005 2013-04-22 16:12
浏览 146
已采纳

传递$ _POST到array_key_exists()时的PHP警告

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.

  • 写回答

2条回答 默认 最新

  • dongshuiga2826 2013-04-22 16:20
    关注

    The Superglobals $_POST and $_GET are only populated if the script is POSTed to or GET from. In your example, the reason that you'd get that error is if there was not post action to the script. Before checking for a certain post value, you should check to make sure there was a post:

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

    In that fashion. From there, you can check for certain values using array_key_exist, or you can further check isset($_POST['myKey']).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度