tags:

views:

75

answers:

2

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);
+1  A: 

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

deceze
+4  A: 

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

Alix Axel
File uploads are not present in `$_POST` or `$_GET`, you have to check `$_FILES` for information on file uploads (and even then the contents are still arrays and strings).
dcousineau
@dcousineau: Are you sure? I believe the `error` index in `$_FILES` holds integers, like `UPLOAD_ERR_OK`.
Alix Axel