Skip to content

Commit c9c7a49

Browse files
gogdzlrodrigoprimo
authored andcommitted
Add documentation for WordPress.PHP.NoSilencedErrors
1 parent 9508e0d commit c9c7a49

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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="Discourage the use of the PHP error silencing operator"
5+
>
6+
<standard>
7+
<![CDATA[
8+
Silencing errors is strongly discouraged. Use proper error checking instead.
9+
10+
Using the error operator with certain functions is allowed because no amount of error checking can fully prevent PHP from throwing errors when these functions are executed. The functions where this is permitted include, but are not limited to:
11+
12+
- `file_exists()`
13+
- `file_get_contents()`
14+
- `filesize()`
15+
- `filetype()`
16+
- `fopen()`
17+
- `ftp_login()`
18+
- `ftp_rename()`
19+
]]>
20+
</standard>
21+
<code_comparison>
22+
<code title="Valid: Using proper error checking when calling functions not in the allowed list.">
23+
<![CDATA[
24+
$conn_id = ftp_connect( $ftp_server );
25+
if ( ! $conn_id ) {
26+
// Handle it as needed.
27+
}
28+
]]>
29+
</code>
30+
<code title="Invalid: Using the error operator to silence errors.">
31+
<![CDATA[
32+
$conn_id = <em>@ftp_connect( $ftp_server );</em>
33+
]]>
34+
</code>
35+
</code_comparison>
36+
</documentation>

0 commit comments

Comments
 (0)