rfc:remove_hex_support_in_numeric_strings
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:remove_hex_support_in_numeric_strings [2014/08/19 17:37] – created nikic | rfc:remove_hex_support_in_numeric_strings [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2014-08-19 | * Date: 2014-08-19 | ||
* Author: Nikita Popov < | * Author: Nikita Popov < | ||
- | * Status: | + | * Status: |
- | * Target version: | + | |
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC proposes to remove support for hexadecimal numers in '' | + | This RFC proposes to remove support for hexadecimal numers in '' |
PHP internally has two primary methods from converting strings into numbers: | PHP internally has two primary methods from converting strings into numbers: | ||
- | The first, and most commonly used, are direct casts to the integer or float types ('' | + | The first, and most commonly used, are direct casts to the integer or float types ('' |
<code php> | <code php> | ||
Line 20: | Line 19: | ||
The second possibility is the '' | The second possibility is the '' | ||
- | This leads to a discrepancy in behavior between | + | This leads to a discrepancy in behavior between |
- | === is_numeric function === | + | === is_numeric() function === |
<code php> | <code php> | ||
Line 30: | Line 29: | ||
} | } | ||
- | // Exception not thrown, instead wrong result is taken here: | + | // Exception not thrown, instead wrong result is generated |
$n = (int) $str; // 0 | $n = (int) $str; // 0 | ||
</ | </ | ||
Line 39: | Line 38: | ||
var_dump(' | var_dump(' | ||
- | var_dump((int) ' | + | var_dump((int) ' |
</ | </ | ||
===== Proposal ===== | ===== Proposal ===== | ||
+ | This RFC proposes to remove support for hexadecimal numbers in '' | ||
+ | |||
+ | An alternative approach would be to add hexadecimal support for integer/ | ||
+ | |||
+ | Generally hexadecimal strings are not often necessary and should be explicitly handled in the cases where they are. A robust way of both validating and parsing hexadecimal strings is given by '' | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
+ | Hexadecimal numbers in strings are no longer supported in the following contexts: | ||
+ | |||
+ | * The '' | ||
+ | * Operands of the '' | ||
+ | * Arguments of internal functions using '' | ||
+ | * Probably some other fringe cases. | ||
+ | |||
+ | Hex string arguments to internal functions will throw the customary "non well formed numeric string" | ||
===== Patch ===== | ===== Patch ===== | ||
+ | |||
+ | Patch available as PR: https:// | ||
===== Vote ===== | ===== Vote ===== | ||
+ | |||
+ | As this is a language change a 2/3 majority is required. | ||
+ | |||
+ | The vote started on 2015-01-17 and ends on 2015-01-27. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
rfc/remove_hex_support_in_numeric_strings.1408469833.txt.gz · Last modified: 2017/09/22 13:28 (external edit)