Skip to content

Commit da15b66

Browse files
authored
Modernise parse_str description (#4556)
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.
1 parent dd100db commit da15b66

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

reference/strings/functions/parse-str.xml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<refentry xml:id="function.parse-str" xmlns="http://docbook.org/ns/docbook">
44
<refnamediv>
55
<refname>parse_str</refname>
6-
<refpurpose>Parses the string into variables</refpurpose>
6+
<refpurpose>Parse a string as a URL query string</refpurpose>
77
</refnamediv>
88

99
<refsect1 role="description">
@@ -15,8 +15,9 @@
1515
</methodsynopsis>
1616
<para>
1717
Parses <parameter>string</parameter> as if it were the query string
18-
passed via a URL and sets variables in the current scope (or in the array
19-
if <parameter>result</parameter> is provided).
18+
passed via a URL and sets keys in the provided <parameter>result</parameter>
19+
array. If no <parameter>result</parameter> is passed, values are instead
20+
set as variables in the current scope.
2021
</para>
2122
</refsect1>
2223

@@ -36,8 +37,10 @@
3637
<term><parameter>result</parameter></term>
3738
<listitem>
3839
<para>
39-
If the second parameter <parameter>result</parameter> is present,
40-
variables are stored in this variable as array elements instead.
40+
A variable passed by reference, which will be set to an array
41+
containing the key-value pairs extracted from <parameter>string</parameter>.
42+
If the <parameter>result</parameter> parameter is not passed,
43+
a separate variable is set in the local scope for each key.
4144
</para>
4245

4346
<warning>
@@ -112,9 +115,10 @@ echo $output['arr'][1], PHP_EOL; // baz
112115
</example>
113116
</para>
114117
<para>
115-
Because variables in PHP can't have dots and spaces in their names,
116-
those are converted to underscores. Same applies to naming of
117-
respective key names in case of using this function with
118+
Any spaces and dots in parameter names are converted to underscores
119+
when creating array keys or local variables.
120+
This is because variable names in PHP are not allowed to contain spaces
121+
or dots, but applies even when using this function with the recommended
118122
<parameter>result</parameter> parameter.
119123
<example>
120124
<title><function>parse_str</function> name mangling</title>
@@ -135,7 +139,7 @@ echo $output['My_Value']; // Something
135139

136140
<note>
137141
<para>
138-
<function>parse_str()</function> is affected by the <link linkend="ini.max-input-vars">max_input_vars</link>
142+
<function>parse_str</function> is affected by the <link linkend="ini.max-input-vars">max_input_vars</link>
139143
directive. Exceeding this limit triggers an <constant>E_WARNING</constant>,
140144
and any variables beyond the limit are not added to the result array.
141145
The default is 1000; adjust <link linkend="ini.max-input-vars">max_input_vars</link> as needed.
@@ -144,13 +148,14 @@ echo $output['My_Value']; // Something
144148

145149
<note>
146150
<para>
147-
All variables created (or values returned into array if second parameter is set)
148-
are already <function>urldecode</function>d.
151+
All values populated in the <parameter>result</parameter> array
152+
(or variables created if second parameter is not set)
153+
are already URL-decoded using the same rules as <function>urldecode</function>.
149154
</para>
150155
</note>
151156
<note>
152157
<para>
153-
To get the current <literal>QUERY_STRING</literal>, you may use the variable
158+
To get the query string of the current request, you may use the variable
154159
<varname>$_SERVER['QUERY_STRING']</varname>.
155160
Also, you may want to read the section on
156161
<link linkend="language.variables.external">variables from external

0 commit comments

Comments
 (0)