Skip to content

Commit 2db69a7

Browse files
author
Fabian Schmengler /
authored
Merge pull request #56 from jissereitsma/doc-strict-types
Implement doc for rule on Strict Types
2 parents ba74750 + c8d381f commit 2db69a7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Rule: Add `declare(strict_types=1)` to your PHP files
2+
## Background
3+
With PHP 7, it is possible to add type hinting to your code. However, this doesn't mean that types are actually enforced, unless strict typing is
4+
enabled by adding `declare(strict_types=1)` to the top of each PHP file.
5+
6+
## Reasoning
7+
PHP code becomes more robust when type hinting (argument types, return types) are added. With the `declare(strict_types=1)` added, there is less
8+
chance for bugs that related to type casting.
9+
10+
## How it works
11+
This rule scans the source code to see whether a line `declare(strict_type=1)` occurs or not.
12+
13+
## How to fix
14+
Simply add a statement `declare(strict_types=1)` to the top of your files:
15+
16+
<?php
17+
declare(strict_types=1);
18+
19+
namespace Foo\Bar;

0 commit comments

Comments
 (0)