From 8e5f7233a7441708b7ebe03c114192645d50c071 Mon Sep 17 00:00:00 2001 From: Rowan Tommins Date: Sat, 22 Mar 2025 15:46:16 +0000 Subject: [PATCH 1/2] Modernise parse_str description Most of the text still acted as though "create a bunch of local variables" was the normal behaviour, even though it's been discouraged for years, and isn't even supported in PHP 8. There were also a few incorrect or questionable uses of markup. --- reference/strings/functions/parse-str.xml | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/reference/strings/functions/parse-str.xml b/reference/strings/functions/parse-str.xml index 9b03d2e3d4eb..38bfdb48b92c 100644 --- a/reference/strings/functions/parse-str.xml +++ b/reference/strings/functions/parse-str.xml @@ -3,7 +3,7 @@ parse_str - Parses the string into variables + Parse a string as a URL query string @@ -15,8 +15,9 @@ Parses string as if it were the query string - passed via a URL and sets variables in the current scope (or in the array - if result is provided). + passed via a URL and sets keys in the provided result + array. If no result is passed, values are instead + set as variables in the current scope. @@ -36,8 +37,10 @@ result - If the second parameter result is present, - variables are stored in this variable as array elements instead. + A variable passed by reference, which will be set to an array + containing the key-value pairs extracted from string. + If the result parameter is not passed, + a separate variable is set in the local scope for each key. @@ -118,9 +121,10 @@ echo $arr[1]; // baz - Because variables in PHP can't have dots and spaces in their names, - those are converted to underscores. Same applies to naming of - respective key names in case of using this function with + Any spaces and dots in parameter names are converted to underscores + when creating array keys or local variables. + This is because variables in PHP can't have dots and spaces in their names, + but applies even when using this function with the recommended result parameter. <function>parse_str</function> name mangling @@ -144,7 +148,7 @@ echo $output['My_Value']; // Something - parse_str() is affected by the max_input_vars + parse_str is affected by the max_input_vars directive. Exceeding this limit triggers an E_WARNING, and any variables beyond the limit are not added to the result array. The default is 1000; adjust max_input_vars as needed. @@ -153,13 +157,14 @@ echo $output['My_Value']; // Something - All variables created (or values returned into array if second parameter is set) - are already urldecoded. + All values populated in the result array + (or variables created if second parameter is not set) + are already URL-decoded as though run through urldecode. - To get the current QUERY_STRING, you may use the variable + To get the query string of the current request, you may use the variable $_SERVER['QUERY_STRING']. Also, you may want to read the section on variables from external From 7ce8e1f1386da58a2e8640bcb7fa3320a259d50f Mon Sep 17 00:00:00 2001 From: Rowan Tommins Date: Sun, 23 Mar 2025 17:01:36 +0000 Subject: [PATCH 2/2] parse_str: tweak wording for easier reading --- reference/strings/functions/parse-str.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/reference/strings/functions/parse-str.xml b/reference/strings/functions/parse-str.xml index 38bfdb48b92c..5102fe7b2299 100644 --- a/reference/strings/functions/parse-str.xml +++ b/reference/strings/functions/parse-str.xml @@ -123,8 +123,8 @@ echo $arr[1]; // baz Any spaces and dots in parameter names are converted to underscores when creating array keys or local variables. - This is because variables in PHP can't have dots and spaces in their names, - but applies even when using this function with the recommended + This is because variable names in PHP are not allowed to contain spaces + or dots, but applies even when using this function with the recommended result parameter. <function>parse_str</function> name mangling @@ -159,7 +159,7 @@ echo $output['My_Value']; // Something All values populated in the result array (or variables created if second parameter is not set) - are already URL-decoded as though run through urldecode. + are already URL-decoded using the same rules as urldecode.