Skip to content

Commit b8d2089

Browse files
authored
DontExtractStandard.xml file creation (#2456)
* Add DontExtractStandard.xml documentation file
1 parent eb39475 commit b8d2089

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0"?>
2+
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
4+
title="Detect Use Of `extract()`"
5+
>
6+
<standard>
7+
<![CDATA[
8+
Forbids the usage of the PHP native `extract()` function. Using `extract()` makes code harder to debug, harder to understand and may cause unexpected behaviour when variables names conflict.
9+
]]>
10+
</standard>
11+
<code_comparison>
12+
<code title="Valid: Accessing array elements directly.">
13+
<![CDATA[
14+
$post_data = array(
15+
'title' => 'My title',
16+
'content' => 'My content',
17+
'ID' => 123
18+
);
19+
<em>echo $post_data['title'];</em>
20+
]]>
21+
</code>
22+
<code title="Invalid: Using the `extract()` function.">
23+
<![CDATA[
24+
$var_array = array(
25+
'title' => 'My title',
26+
'content' => 'My content',
27+
'ID' => 123
28+
);
29+
30+
<em>extract( $var_array );</em>
31+
echo $title;
32+
]]>
33+
</code>
34+
</code_comparison>
35+
</documentation>

0 commit comments

Comments
 (0)