Skip to content

Commit 1709768

Browse files
authored
FAQ: Mention named arguments and discourage manual escaping (#5377)
Updates the FAQ: - Mentions named arguments in the parameter order entry. - Adds a note discouraging manual escaping in the addslashes entry, recommending prepared statements and parameter binding instead.
1 parent 6122a83 commit 1709768

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

faq/using.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<qandaset>
1313

1414
<qandaentry xml:id="faq.using.parameterorder">
15-
<!-- TODO: Mention named arguments -->
1615
<question>
1716
<para>
1817
I cannot remember the parameter order of PHP functions, are they random?
@@ -29,6 +28,10 @@
2928
<link linkend="book.strings">String functions</link> are the opposite,
3029
so "<emphasis>haystack, needle</emphasis>".
3130
</para>
31+
<para>
32+
As of PHP 8.0, <link linkend="functions.named-arguments">named arguments</link>
33+
allow passing arguments by parameter name, making parameter order less of a concern.
34+
</para>
3235
</answer>
3336
</qandaentry>
3437

@@ -79,7 +82,6 @@ if (empty($empty)) {
7982
</qandaentry>
8083

8184
<qandaentry xml:id="faq.using.addslashes">
82-
<!-- TODO Probably should mention not doing this... -->
8385
<question>
8486
<para>
8587
I need to convert all single-quotes (') to a backslash
@@ -98,6 +100,12 @@ if (empty($empty)) {
98100
<function>stripslashes</function> functions, that are more
99101
common with older PHP code.
100102
</para>
103+
<para>
104+
Manually escaping values is error-prone and depends on context.
105+
Prefer using database APIs that support prepared statements and
106+
parameter binding instead of constructing queries by concatenating
107+
escaped strings.
108+
</para>
101109
</answer>
102110
</qandaentry>
103111

0 commit comments

Comments
 (0)