rfc:saner-numeric-strings
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:saner-numeric-strings [2020/07/15 16:13] – Add missing bitwise example theodorejb | rfc:saner-numeric-strings [2020/07/16 13:18] – Enable voting girgias | ||
---|---|---|---|
Line 12: | Line 12: | ||
A string can be categorised in three ways according to its numeric-ness, | A string can be categorised in three ways according to its numeric-ness, | ||
- | * A //numeric string// is a string containing only a [[https:// | + | * A //numeric string// is a string containing only a [[https:// |
- | * A // | + | * A // |
* A // | * A // | ||
A fourth way PHP might deal with numeric strings is when using an //integer// string for an array index. | A fourth way PHP might deal with numeric strings is when using an //integer// string for an array index. | ||
An integer string is stricter than a numeric string as it has the following additional constraints: | An integer string is stricter than a numeric string as it has the following additional constraints: | ||
- | * It doesn' | + | * It doesn' |
* It doesn' | * It doesn' | ||
Line 27: | Line 27: | ||
" | " | ||
" | " | ||
- | " 1" => " | + | " 1" => " |
" | " | ||
]; | ]; | ||
Line 43: | Line 43: | ||
string(22) " | string(22) " | ||
[" 1" | [" 1" | ||
- | string(19) " | + | string(19) " |
[" | [" | ||
string(5) " | string(5) " | ||
Line 101: | Line 101: | ||
var_dump(123 + " | var_dump(123 + " | ||
</ | </ | ||
- | * Increment/Decrement | + | * Increment/decrement |
$a = " | $a = " | ||
var_dump(++$a); | var_dump(++$a); | ||
Line 134: | Line 134: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | Unify the various numeric string modes into a single concept: Numeric characters only with both leading and trailing | + | Unify the various numeric string modes into a single concept: Numeric characters only with both leading and trailing |
- | This means, all strings which currently emit the < | + | This means, all strings which currently emit the < |
One exception to this are type declarations as they only accept proper numeric strings, thus some < | One exception to this are type declarations as they only accept proper numeric strings, thus some < | ||
Line 153: | Line 153: | ||
foo(" | foo(" | ||
</ | </ | ||
- | * < | + | * < |
- | var_dump(is_numeric(" | + | var_dump(is_numeric(" |
</ | </ | ||
* String offsets< | * String offsets< | ||
Line 167: | Line 167: | ||
var_dump(123 + " | var_dump(123 + " | ||
</ | </ | ||
- | * The < | + | * The < |
$d = "5 "; | $d = "5 "; | ||
var_dump(++$d); | var_dump(++$d); | ||
Line 188: | Line 188: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
There are three backward incompatible changes: | There are three backward incompatible changes: | ||
- | * Code relying on numerical strings with trailing | + | * Code relying on numerical strings with trailing |
* Code with liberal use of leading-numeric strings might need to use explicit type casts. | * Code with liberal use of leading-numeric strings might need to use explicit type casts. | ||
- | * Code relying on the fact that < | + | * Code relying on the fact that < |
The first reason is a precise requirement and therefore should be checked explicitly. A small poly-fill to check for the previous < | The first reason is a precise requirement and therefore should be checked explicitly. A small poly-fill to check for the previous < | ||
Line 197: | Line 197: | ||
Breaking the second reason will allow to catch various bugs ahead of time, and the previous behaviour can be obtained by adding explicit casts, e.g.: | Breaking the second reason will allow to catch various bugs ahead of time, and the previous behaviour can be obtained by adding explicit casts, e.g.: | ||
<PHP> | <PHP> | ||
- | var_dump((int) " | + | var_dump((int) " |
- | var_dump((float) " | + | var_dump((float) " |
- | var_dump((int) " | + | var_dump((int) " |
var_dump((float) " | var_dump((float) " | ||
</ | </ | ||
Line 220: | Line 220: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
* Nikita Popov' | * Nikita Popov' | ||
- | * Adding an E_NOTICE for numerical strings with leading/ | + | * Adding an E_NOTICE for numerical strings with leading/ |
- | * Adding a flag to < | + | * Adding a flag to < |
* Align string offset behaviour with array offsets | * Align string offset behaviour with array offsets | ||
* Promote remaining warnings to Type Errors in PHP 9 | * Promote remaining warnings to Type Errors in PHP 9 | ||
Line 228: | Line 228: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Per the Voting RFC, there would be a single Yes/No vote requiring a 2/3 majority for the main proposal. A secondary Yes/No vote requiring a 50%+1 majority will decide whether float strings used as string offsets should continue to produce a warning (with different wording) instead of consistently becoming a TypeError. | Per the Voting RFC, there would be a single Yes/No vote requiring a 2/3 majority for the main proposal. A secondary Yes/No vote requiring a 50%+1 majority will decide whether float strings used as string offsets should continue to produce a warning (with different wording) instead of consistently becoming a TypeError. | ||
+ | |||
+ | Primary vote: | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | Secondary vote: | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== |
rfc/saner-numeric-strings.txt · Last modified: 2020/11/25 12:46 by girgias