【问题标题】:what's the type of the value assigned by $_GET['x'] and $_POST['x']?$_GET['x'] 和 $_POST['x'] 分配的值的类型是什么?
【发布时间】:2018-06-29 00:08:45
【问题描述】:
//include.php?filepath=theme.php (string)
//include.php?filepath=0 (int)
//include.php?filepath=[] (null)
$file = $_GET['filepath'];
if ($file != "theme.php")
{
   die("error file is not a theme");
}
include($file);

在上面的代码中,sn -p 第 2 行的比较是什么?字符串 VS 字符串还是字符串 VS 整数?

换句话说,$_GET['x'] 会返回什么?

【问题讨论】:

  • 它总是一个字符串
  • @YouneL 你能给出一个总是如此的概念证明吗?我在文档中的任何地方都找不到它
  • 嗯,$_GET 是一个由查询字符串产生的关联数组
  • @AK_,参见$_GET 描述页面。它有一个注释,“GET 变量是通过 urldecode() 传递的”。而urldecode 函数总是返回一个字符串。
  • @SergeyRonin 这回答了我的问题。您能否将其发布为包含所有详细信息和引用来源的答案?谢谢

标签: php string web-applications types comparison


【解决方案1】:

$_GET 数组始终包含字符串。当 PHP 处理查询字符串时,查询中的每个变量都会通过 urldecode 函数传递,该函数总是返回一个字符串。

来自$_GET变量描述的注释:

注意:

GET 变量通过 urldecode() 传递。

【讨论】:

    【解决方案2】:

    在这个链接中你可以看到超级全局变量是字符串类型的 Here

    【讨论】:

      猜你喜欢
      • 2010-11-23
      • 2019-10-30
      • 2020-08-25
      • 1970-01-01
      • 2018-08-18
      • 2021-03-20
      • 1970-01-01
      • 2021-03-02
      • 2019-12-04
      相关资源
      最近更新 更多