rfc:normalize_inc_dec
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | rfc:normalize_inc_dec [2014/02/01 05:32] – datibbaw | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== PHP RFC: Normalize increment and decrement operators ====== | ||
+ | * Version: 0.1 | ||
+ | * Date: 2013-12-19 | ||
+ | * Author: Tjerk Meesters (datibbaw) | ||
+ | * Status: Draft | ||
+ | * First Published at: https:// | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | The current behaviour of increment and decrement operators is not very intuitive: | ||
+ | |||
+ | <code php> | ||
+ | // booleans | ||
+ | $a = false; ++$a; // bool(false) | ||
+ | $a = true; --$a; // bool(true) | ||
+ | |||
+ | // null values | ||
+ | $a = null; --$a; // null | ||
+ | $a = null; ++$a; // int(1) | ||
+ | |||
+ | // empty strings | ||
+ | $a = ''; | ||
+ | |||
+ | // non-numeric strings | ||
+ | $a = ' | ||
+ | ++$a; // string(4) " | ||
+ | ++$a; // float(13) | ||
+ | </ | ||
+ | |||
+ | ===== Proposal ===== | ||
+ | |||
+ | The proposal is either: | ||
+ | - Treat boolean and null types as a restricted type value and deprecate alphanumeric increment. | ||
+ | - Treat boolean and null types as an integer value and deprecate alphanumeric increment. | ||
+ | - No changes. | ||
+ | |||
+ | ==== Option 1: Restricted type values ==== | ||
+ | |||
+ | <code php> | ||
+ | // booleans | ||
+ | $a = false; | ||
+ | ++$a; // bool(true) | ||
+ | ++$a; // bool(true) | ||
+ | $a = true; | ||
+ | --$a; // bool(false) | ||
+ | --$a; // bool(false) | ||
+ | |||
+ | // null values | ||
+ | $a = null; --$a; // null | ||
+ | $a = null; ++$a; // null | ||
+ | |||
+ | // empty strings | ||
+ | $a = ''; | ||
+ | </ | ||
+ | |||
+ | ==== Option 2: Integer values ==== | ||
+ | |||
+ | <code php> | ||
+ | // booleans | ||
+ | $a = false; | ||
+ | ++$a; // bool(true) | ||
+ | ++$a; // int(2) | ||
+ | $a = true; | ||
+ | --$a; // bool(false) | ||
+ | --$a; // int(-1) | ||
+ | |||
+ | // null values | ||
+ | $a = null; --$a; // int(-1) | ||
+ | $a = null; ++$a; // int(1) | ||
+ | </ | ||
+ | |||
+ | ==== Deprecating alphanumeric string increment ==== | ||
+ | |||
+ | <code php> | ||
+ | // non-numeric strings | ||
+ | $a = ' | ||
+ | ++$a; // string(4) " | ||
+ | ++$a; // float(13) | ||
+ | </ | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== Backward Incompatible Changes ===== | ||
+ | |||
+ | With " | ||
+ | |||
+ | ===== Proposed PHP Version(s) ===== | ||
+ | |||
+ | **Next 5.x** | ||
+ | |||
+ | 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 ===== | ||
+ | |||
+ | None. | ||
+ | |||
+ | ===== Unaffected PHP Functionality ===== | ||
+ | |||
+ | The changes do not affect the following data types: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== Proposed Voting Choices ===== | ||
+ | |||
+ | Yay or nay. | ||
+ | |||
+ | ===== Patches and Tests ===== | ||
+ | |||
+ | Coming soon ... | ||
+ | |||
+ | ===== Implementation ===== | ||
+ | |||
+ | N/A | ||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | The competing proposal: | ||
+ | |||
+ | [[alpanumeric_decrement|Alphanumeric Decrement]] | ||
+ | |||
+ | ===== Rejected Features ===== | ||
+ | |||
+ | Keep this updated with features that were discussed on the mail lists. |
rfc/normalize_inc_dec.txt · Last modified: 2018/06/18 10:17 by cmb