|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-07-02 20:11 UTC] barry at yourang dot org
Description: ------------ Prior to PHP 5.6, POSTing "invalid" urlencoded data would result in $_POST being an empty array. In PHP 5.6, PHP now populates $_POST, which is unexpected. This change seems backwards incompatible with previous versions of PHP and nothing is mentioned in the documentation that I can find. Test script: --------------- Both of these URLs just do: <?php var_dump($_POST); PHP 5.5.24 $ curl http://viper-7.com/hOubxq/5.5.24/ --data 'key' array(0) { } PHP 5.6.10 $ curl http://viper-7.com/h0PMyx/5.6.10/ --data 'key' array(1) { ["key"]=> string(0) "" } Expected result: ---------------- I would expect the POST request to result in an empty $_POST array in 5.6 just like 5.5 Actual result: -------------- $_POST is populated with data. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
I am not sure if the new behavior is correct or incorrect, but it's definitely different and seemingly not mentioned in the documentation. A more real-world example is POSTing JSON using the wrong Content-Type header (apparently clients do this). In PHP <= 5.6.0 you would end up with an empty $_POST, now you have this: curl --data '{ "key": "value" }' http://viper-7.com/h0PMyx/5.6.10/ array(1) { ["{_"key":_"value"_}"]=> string(0) "" } This is different than what you have if the correct "Content-Type: application/json" header is set in the request: curl -H "Content-Type: application/json" --data '{ "key": "value" }' http://viper-7.com/h0PMyx/5.6.10/ array(0) { } In older versions of PHP you would end up with empty $_POST in either case. I think I would consider this change a regression, but if it's determined that it was intentional, I think the docs should at least be updated to reflect the new behavior because it's backwards incompatible if you were expecting $_POST to be empty, etc.