duanchi8836 2011-05-03 19:47
浏览 690
已采纳

@ $ _ GET是什么意思?

I don't understand why someone is using the @ in the code, I have seen it with mysql connections but I don't know what it means.. thanks!

$player_name_orig = @$_GET['player'];
if (!$player_name_orig) {
    die('You must specify a player name');
}
  • 写回答

4条回答 默认 最新

  • dpwjx32578146 2011-05-03 19:49
    关注

    The @ is the error suppression operator.

    In this specific context, it's a (wrong!) way to avoid PHP giving a notice if the player key does not exist in $_GET:

    If you try this:

    unset($_GET['player']); // to make sure
    echo $_GET['player'];
    

    You get:

    Notice: Undefined index: player in F:\dev\www\index.php on line 35

    While if you try this:

    unset($_GET['player']); // to make sure
    echo @$_GET['player'];
    

    There is no output.

    The correct way to do this:

    if (empty($_GET['player']) {
        die('You must specify a player name');
    }  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记