Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible types of $_POST and $_GET values

Tags:

types

php

Is it possible for there to by any type of value in $_GET or $_POST which is not an array or string?

For those who read code better, is it at all possible to run this simple script on a web server and get it to throw the exception?

// 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);
like image 814
too much php Avatar asked Aug 28 '09 01:08

too much php


2 Answers

Except for file uploads, values are always strings or arrays.

like image 123
Alix Axel Avatar answered Nov 07 '22 15:11

Alix Axel


I believe in the case of file uploads, the 'error' and 'size' fields would be ints.

like image 43
deceze Avatar answered Nov 07 '22 15:11

deceze