rfc:null_coercion_consistency
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:null_coercion_consistency [2022/04/09 08:49] – Add user-defined function example craigfrancis | rfc:null_coercion_consistency [2022/04/11 16:32] – Update note about user-defined functions specifying parameter types (thanks George Peter Banyard) craigfrancis | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: NULL Coercion Consistency ====== | ====== PHP RFC: NULL Coercion Consistency ====== | ||
- | * Version: 0.1 | + | * Version: 0.2 |
* Voting Start: ? | * Voting Start: ? | ||
* Voting End: ? | * Voting End: ? | ||
Line 20: | Line 20: | ||
Roughly **85%** scripts do not use // | Roughly **85%** scripts do not use // | ||
- | Roughly **33%** of developers use static analysis (optimistic, details below). | + | Roughly **33%** of developers use static analysis (realistically it's less than this, details below). |
There was a [[https:// | There was a [[https:// | ||
- | ===== Documentation | + | ===== Problem |
+ | |||
+ | ==== Documentation | ||
According to the documentation, | According to the documentation, | ||
- | Where coercion | + | Coercion |
- [[https:// | - [[https:// | ||
Line 68: | Line 70: | ||
</ | </ | ||
- | With user-defined functions, while this does not cause a backwards compatibility issue (details below), it still highlights the coercion | + | With user-defined functions, while this does not cause a backwards compatibility issue (details below), it still highlights the coercion |
<code php> | <code php> | ||
function user_function(string $s, int $i, float $f, bool $b) { | function user_function(string $s, int $i, float $f, bool $b) { | ||
var_dump($s, | var_dump($s, | ||
- | echo " | ||
} | } | ||
Line 98: | Line 99: | ||
NULL can usually be coerced, but... | NULL can usually be coerced, but... | ||
- | - PHP 7.0 introduced the ability for user-defined functions to specify parameter types via the [[https:// | + | - PHP 7.0 introduced the ability for user-defined functions to specify parameter types via the [[https:// |
- PHP 8.1 continued this inconsistency with internal functions. | - PHP 8.1 continued this inconsistency with internal functions. | ||
- | ===== Examples | + | ==== Examples ==== |
Common sources of NULL: | Common sources of NULL: | ||
Line 122: | Line 123: | ||
</ | </ | ||
- | Examples where NULL has been fine for scripts not using // | + | Examples where NULL has previously |
<code php> | <code php> | ||
Line 156: | Line 157: | ||
There are approximately [[https:// | There are approximately [[https:// | ||
- | As an aside, there are also roughly [[https:// | + | As an aside, there are also roughly [[https:// |
- | ===== Finding | + | ==== Finding ==== |
The only realistic way for developers to find when NULL is passed to these internal functions is to use the deprecation notices (not ideal). | The only realistic way for developers to find when NULL is passed to these internal functions is to use the deprecation notices (not ideal). | ||
- | 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. | + | 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, | + | In the last JetBrains developer survey, |
As an example, take this simple script: | As an example, take this simple script: | ||
Line 249: | Line 250: | ||
Note: Juliette (@jrfnl) has confirmed that getting PHPCompatibility to solve this problem will be " | Note: Juliette (@jrfnl) has confirmed that getting PHPCompatibility to solve this problem will be " | ||
- | ===== Temporary Solutions | + | ==== Temporary Solutions ==== |
You can disable // | You can disable // | ||
Line 268: | Line 269: | ||
And some developers are simply [[https:// | And some developers are simply [[https:// | ||
- | ===== Updating | + | ==== Updating ==== |
While making each change is fairly easy - they are difficult to find, there are many of them (time consuming), and the updates used are often pointless, e.g. | While making each change is fairly easy - they are difficult to find, there are many of them (time consuming), and the updates used are often pointless, e.g. | ||
Line 291: | Line 292: | ||
Must keep the spirit of the original RFC, and keep user-defined and internal functions consistent. | Must keep the spirit of the original RFC, and keep user-defined and internal functions consistent. | ||
- | But continue to support | + | Revert the deprecation of NULL coercion |
- | The current intention of causing Fatal Errors in 9.0 will make upgrading very difficult. | + | For consistency, |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 321: | Line 322: | ||
" | " | ||
- | " | + | " |
===== Future Scope ===== | ===== Future Scope ===== | ||
- | Some function parameters could be updated to rase a Fatal Error when //NULL// **or** //Empty String// is provided; e.g. //$method// in //method_exists()//, or // | + | Some function parameters could be updated to rase a Fatal Error when //NULL// **or** //Empty String// is provided; e.g. |
+ | |||
+ | - //$needle// in [[https://php.net/ | ||
+ | - // | ||
+ | - //$method// in [[https:// | ||
+ | - //$json// in [[https:// | ||
===== Voting ===== | ===== Voting ===== |
rfc/null_coercion_consistency.txt · Last modified: 2023/10/18 11:57 by craigfrancis