Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $_GET['key'] return if the key is not set?

Tags:

arrays

php

get

What does $_GET return when the index is not set? (Couldn't find anything in php manual about $_GET.)

I wrote this to check, if the $_GET['id'] isset - and if it is not, set $id to false:

<?php $id = (isset($_GET['id'])) ? $_GET['id'] : false ?>
like image 780
Rihards Avatar asked Jul 01 '10 13:07

Rihards


2 Answers

$_GET is just an ordinary array, so it behaves exactly the same as any other array.

This means, it will return NULL to the variable and raise the "undefined index" notice when you call a non-existing index.

The only thing you need to be aware of with $_GET is that is contains unsafe (user-modifiable) data

like image 172
alexanderpas Avatar answered Oct 07 '22 14:10

alexanderpas


Unset indexes have the value NULL. Accessing them will result in a notice being raised (unless your error level is set to swallow notices).

like image 43
igorw Avatar answered Oct 07 '22 13:10

igorw