Rule declare_strict_types¶
Force strict types declaration in all files.
Warnings¶
This rule is RISKY¶
Forcing strict types will stop non strict code from working.
This rule is CONFIGURABLE¶
You can configure this rule using the following option:
preserve_existing_declaration.
Configuration¶
preserve_existing_declaration¶
Whether existing strict_types=? should be preserved and not overridden.
Allowed types: bool
Default value: false
Examples¶
Example #1¶
Default configuration.
--- Original
+++ New
-<?php
+<?php declare(strict_types=1);
\ No newline at end of file
Example #2¶
With configuration: ['preserve_existing_declaration' => false].
--- Original
+++ New
<?php
-declare(Strict_Types=0);
+declare(strict_types=1);
Example #3¶
With configuration: ['preserve_existing_declaration' => true].
--- Original
+++ New
<?php
-declare(Strict_Types=0);
+declare(strict_types=0);
Rule sets¶
The rule is part of the following rule sets:
@PHP70Migration:risky (deprecated)
@PHP71Migration:risky (deprecated)
@PHP74Migration:risky (deprecated)
@PHP80Migration:risky (deprecated)
@PHP82Migration:risky (deprecated)
References¶
Fixer class: PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer
Test class: PhpCsFixer\Tests\Fixer\Strict\DeclareStrictTypesFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.