rfc:normalize_inc_dec
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:normalize_inc_dec [2013/12/19 10:34] – datibbaw | rfc:normalize_inc_dec [2017/09/22 13:28] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Normalize increment and decrement operators ====== | ====== PHP RFC: Normalize increment and decrement operators ====== | ||
- | * Version: 0.1 | + | * Version: 0.2 |
* Date: 2013-12-19 | * Date: 2013-12-19 | ||
- | * Author: | + | * Author: |
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This proposal aims to make the current behaviour | + | The current behaviour |
<code php> | <code php> | ||
Line 18: | Line 18: | ||
// null values | // null values | ||
$a = null; --$a; // null | $a = null; --$a; // null | ||
+ | $a = null; ++$a; // int(1) | ||
// empty strings | // empty strings | ||
Line 28: | Line 29: | ||
</ | </ | ||
- | For strings, it makes two new functions available: | + | ===== Proposal ===== |
- | * '' | + | The proposal is: |
- | * '' | + | - always treat boolean and null types as an integer, but raise a warning. |
+ | - deprecate alphanumeric increment and introduce | ||
- | ===== Proposal | + | ==== Operation on bool / null ==== |
- | + | ||
- | The following behaviour is being proposed: | + | |
<code php> | <code php> | ||
// booleans | // booleans | ||
- | $a = false; ++$a; // int(1) | + | $a = false; |
- | $a = true; --$a; // int(0) | + | ++$a; // int(1) + warning |
+ | ++$a; // int(2) | ||
+ | $a = true; | ||
+ | --$a; // int(0) + warning | ||
+ | --$a; // int(-1) | ||
// null values | // null values | ||
- | $a = null; --$a; // int(-1) | + | $a = null; --$a; // int(-1) |
+ | $a = null; ++$a; // int(1) + warning | ||
+ | </ | ||
- | // empty strings | + | ==== Operation on alphanumeric |
- | $a = ''; | + | |
+ | <code php> | ||
// non-numeric strings | // non-numeric strings | ||
$a = ' | $a = ' | ||
Line 53: | Line 59: | ||
++$a; // float(13) | ++$a; // float(13) | ||
</ | </ | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | None, since incrementing boolean and null values wasn't possible in the first place. | + | Incrementing '' |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | **Next 5.x** | + | **PHP 7** |
- | + | ||
- | Introduce a notice for the current string increment use case. This will help developers spot their usage more easily. | + | |
- | + | ||
- | **Next major** | + | |
- | + | ||
- | Removal of string increment using ++ and --. | + | |
===== Open Issues ===== | ===== Open Issues ===== |
rfc/normalize_inc_dec.txt · Last modified: 2018/06/18 10:17 by cmb