This is an old revision of the document!
PHP RFC: Add parse_query_string as an alternative to parse_str
- Date: 2021-06-23
- Author: Kamil Tekiela dharman@php.net
- Status: Discussion
- Implementation: https://github.com/php/php-src/pull/7344
- Target Version: PHP 8.1
Introduction
PHP offers a function for parsing query string into an array. The function historically has been a mockery as it allowed to register the values as global variables. Since PHP 8.0 this is no longer possible. The function still has two main downsides: a confusing name, and no return value (it returns by out parameter instead).
$str = "first=value&arr[]=foo+bar&arr[]=baz"; parse_str($str, $output); echo $output['first']; // value echo $output['arr'][0]; // foo bar echo $output['arr'][1]; // baz
Proposal
The proposal is to create a new function as a copy of parse_str() but change the name to parse_query_string() and return the array instead of using the out parameter. The new function will take only one argument.
The new function will also be maintained in the manual under https://www.php.net/manual/en/ref.url.php instead of https://www.php.net/manual/en/ref.strings.php
$str = "first=value&arr[]=foo+bar&arr[]=baz"; $output = parse_query_string($str); echo $output['first']; // value echo $output['arr'][0]; // foo bar echo $output['arr'][1]; // baz
Future Scope
The parse_str() function will get deprecated in the next minor release and removed in the next major release.
Backward Incompatible Changes
There will be no breaking change to existing functionality. The new function is designed to give users a way to move away from parse_str() so that we can deprecate it and remove it.
Vote
Simple yes/no vote.