php - $_POST 和 $_GET 值的可能类型

标签 php types

$_GET$_POST不是数组或字符串?

对于那些更善于阅读代码的人来说,是否有可能在网络服务器上运行这个简单的脚本并让它抛出异常?

// crash-me.php
<?php

function must_be_array_or_string($value) {
    if(is_string($value))
        return;
    if(is_array($value)) {
        foreach($value as $subValue)
            must_be_array_or_string($subValue);
        return;
    }
    throw new Exception("Value is " . gettype($value));
}

if(isset($_GET))
    must_be_array_or_string($_GET);

if(isset($_POST))
    must_be_array_or_string($_POST);

最佳答案

除了文件上传,值总是字符串或数组。

关于php - $_POST 和 $_GET 值的可能类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1344576/

相关文章:

php - 如何在 Windows 上为 Cassandra 安装 Datastax-PHP 驱动程序?

php - 用于请求/跟踪功能或错误的 Azure DevOps 自定义页面

c++ - 如何解决 MSVC 2012 中的 `using K = ...`?

python - Pandas 报告系列在小数时是一个对象

c# - 通过反射获取某个C#类型的.Net对应类型

php - 为什么 'use' 语句不能在包含文件中?

PHP flock() 非阻塞还是阻塞为什么?

php - 使用散列加查询字符串作为 jquery 插入网页的 anchor ?

javascript - 如何在 Typescript 中用静态变量表达构造函数?

c - 使用宏进行类型检查