note 98419 added to reserved.variables.get

From: Date: Tue, 15 Jun 2010 00:57:04 +0000
Subject: note 98419 added to reserved.variables.get
Groups: php.notes 
Request: Send a blank email to php-notes+get-170127@lists.php.net to get a copy of this message
Just a note, because I didn't know for sure until I tested it. If you have a query string that contains a parameter but no value (not even an equals sign), like so: http://path/to/script.php?a The following script is a good test to determine how a is valued: <pre> <?php print_r($_GET); if($_GET["a"] === "") echo "a is an empty string\n"; if($_GET["a"] === false) echo "a is false\n"; if($_GET["a"] === null) echo "a is null\n"; if(isset($_GET["a"])) echo "a is set\n"; if(!empty($_GET["a"])) echo "a is not empty"; ?> </pre> I tested this with script.php?a, and it returned: a is an empty string a is set So note that a parameter with no value associated with, even without an equals sign, is considered to be an empty string (""), isset() returns true for it, and it is considered empty, but not false or null. Seems obvious after the first test, but I just had to make sure. Of course, if I do not include it in my browser query, the script returns Array ( ) a is null ---- Server IP: 69.147.83.197 Probable Submitter: 72.208.240.199 ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.get.php Edit -- https://master.php.net/note/edit/98419 Del: integrated -- https://master.php.net/note/delete/98419/integrated Del: useless -- https://master.php.net/note/delete/98419/useless Del: bad code -- https://master.php.net/note/delete/98419/bad+code Del: spam -- https://master.php.net/note/delete/98419/spam Del: non-english -- https://master.php.net/note/delete/98419/non-english Del: in docs -- https://master.php.net/note/delete/98419/in+docs Del: other reasons-- https://master.php.net/note/delete/98419 Reject -- https://master.php.net/note/reject/98419 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170127) next »