rfc:null_coercion_consistency
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
rfc:null_coercion_consistency [2022/05/11 12:07] – Update Future Scope to note difference in casting/converting vs coercion craigfrancis | rfc:null_coercion_consistency [2022/10/16 07:37] – Note that Rector can now "help" with this problem. craigfrancis | ||
---|---|---|---|
Line 106: | Line 106: | ||
</ | </ | ||
- | Arrays, Resources, and Objects (without | + | Arrays, Resources, and Objects (without |
String/ | String/ | ||
Line 210: | Line 210: | ||
It is possible to use very strict Static Analysis, to follow every variable from source to sink (to check if a variable could be NULL), but most developers are not in a position to do this (i.e. not using static analysis, or not at a high enough level, or they are using a baseline to ignore). | It is possible to use very strict Static Analysis, to follow every variable from source to sink (to check if a variable could be NULL), but most developers are not in a position to do this (i.e. not using static analysis, or not at a high enough level, or they are using a baseline to ignore). | ||
- | In the last JetBrains developer survey (with 67% regularly using Laravel), **only 33% used Static Analysis** ([[https:// | + | In the last JetBrains developer survey (with 67% regularly using Laravel), **only 33% used Static Analysis** ([[https:// |
As an example, take this simple script: | As an example, take this simple script: | ||
Line 222: | Line 222: | ||
</ | </ | ||
- | Even that is considered fine today by the relevant | + | This is considered fine by these tools: |
- | + | ||
- | <code cli> | + | |
- | composer require --dev rector/ | + | |
- | ./ | + | |
- | ./ | + | |
- | [OK] Rector is done! | + | |
- | </ | + | |
<code cli> | <code cli> | ||
Line 294: | Line 287: | ||
</ | </ | ||
Note: Psalm can detect this at [[https:// | Note: Psalm can detect this at [[https:// | ||
+ | |||
+ | ==== One Solution ==== | ||
+ | |||
+ | Since [[https:// | ||
+ | |||
+ | <code cli> | ||
+ | mkdir -p rector/src; | ||
+ | |||
+ | cd rector/; | ||
+ | |||
+ | composer require --dev rector/ | ||
+ | |||
+ | echo '<? | ||
+ | |||
+ | echo '<? | ||
+ | |||
+ | use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; | ||
+ | use Rector\Config\RectorConfig; | ||
+ | |||
+ | return static function (RectorConfig $rectorConfig): | ||
+ | $rectorConfig-> | ||
+ | $rectorConfig-> | ||
+ | }; | ||
+ | ' > rector.php; | ||
+ | |||
+ | ./ | ||
+ | </ | ||
+ | |||
+ | This will litter the code with the use of // | ||
+ | |||
+ | <code diff> | ||
+ | -<?= htmlspecialchars($var) ?> | ||
+ | +<?= htmlspecialchars((string) $var) ?> | ||
+ | </ | ||
+ | |||
+ | For a typical project (which won't be using strict_types), | ||
==== Temporary Solutions ==== | ==== Temporary Solutions ==== | ||
Line 329: | Line 358: | ||
</ | </ | ||
- | As noted above - PHPCompatibility, | + | As noted above - Rector |
===== Proposal ===== | ===== Proposal ===== |
rfc/null_coercion_consistency.txt · Last modified: 2023/10/18 11:57 by craigfrancis