php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74727 Values in $_GET/POST are always strings
Submitted: 2017-06-09 11:02 UTC Modified: 2017-08-11 18:54 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:2 of 3 (66.7%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: kmgkumar28 at gmail dot com Assigned: patrickallaert (profile)
Status: Closed Package: Variables related
PHP Version: 7.2.0alpha1 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kmgkumar28 at gmail dot com
New email:
PHP Version: OS:

 

 [2017-06-09 11:02 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-09 11:34 UTC] requinix@php.net
-Summary: Bug in gettype() function +Summary: Values in $_GET/POST are always strings -Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: PHP Language Specification +Package: Variables related
 [2017-06-09 11:34 UTC] 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 12:31 UTC] 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 13:18 UTC] cmb@php.net
> 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>
 [2017-08-11 18:49 UTC] patrickallaert@php.net
Automatic comment from SVN on behalf of patrickallaert
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=342844
Log: Fixed: doc bug 74727
 [2017-08-11 18:54 UTC] patrickallaert@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: patrickallaert
 [2017-08-11 18:54 UTC] patrickallaert@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Documentation was indeed a bit misleading, added a comment on the fact that everything coming as strings per the HTTP protocol, PHP doesn't apply any kind of conversion on those input.

Fixed in the documentation as per SVN revision r342844.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 21:01:24 2019 UTC