Doc #74727 [Ver]: Values in $_GET/POST are always strings

From: Date: Fri, 09 Jun 2017 13:18:18 +0000
Subject: Doc #74727 [Ver]: Values in $_GET/POST are always strings
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14773@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74727&edit=1 ID: 74727 Updated by: cmb@php.net Reported by: kmgkumar28 at gmail dot com Summary: Values in $_GET/POST are always strings Status: Verified Type: Documentation Problem Package: Variables related Operating System: Windows 7 PHP Version: 7.2.0alpha1 Block user comment: N Private report: N New Comment: > I don't actually see this documented, though I do think it has > been somewhere... Actually, the section "Determining variable types"[1] is even rather misleading. [1] <https://secure.php.net/manual/en/language.variables.external.php#language.variables.determining-type-of> Previous Comments: ------------------------------------------------------------------------ [2017-06-09 12:31:38] xpigeon at 163 dot com May be some Error in your form? Your will edit the form like as <form action="?" method="post"> or <form action="?" method="get"> test it again. ------------------------------------------------------------------------ [2017-06-09 11:34:09] requinix@php.net As the new summary says, values in $_GET and $_POST are strings. Well, strings or arrays. Naturally that is the same for $_REQUEST. And it's the case for $_COOKIE too. And even $_SERVER and $_ENV. Anyways, PHP will not try to determine integers or floats, and definitely will not interpret the string "null" to be literally NULL. I don't actually see this documented, though I do think it has been somewhere... https://secure.php.net/manual/en/language.variables.external.php ------------------------------------------------------------------------ [2017-06-09 11:02:48] kmgkumar28 at gmail dot com Description: ------------ In Using The following code the datatype does not returns correctly in output. i sent name value in '123' in html page but here i will only get string value, in similar results in if i set name = 12.32 , null. <html> <form name = "post" > <input type = "text" name = "name" /> <input type = "submit" name = "submit" /> <?php echo gettype($_POST['name']); ?> Expected result: ---------------- 1) if i set the html text box value as number it returns integer 2) if i set the html text box value as text it returns string 3) if i set the html text box value as null it returns NULL Actual result: -------------- 1) i set the html text box value as number it returns string 2) i set the html text box value as text it returns string 3) i set the html text box value as null it returns string ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74727&edit=1

« previous php.doc.bugs (#14773) next »