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 revision | |||
— | rfc:normalize_inc_dec [2018/06/18 10:17] (current) – This RFC appears to be inactive cmb | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== PHP RFC: Normalize increment and decrement operators ====== | ||
+ | * Version: 0.2 | ||
+ | * Date: 2013-12-19 | ||
+ | * Author: Tjerk Meesters (datibbaw) | ||
+ | * Status: Inactive | ||
+ | * 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: | ||
+ | - always treat boolean and null types as an integer, but raise a warning. | ||
+ | - deprecate alphanumeric increment and introduce '' | ||
+ | |||
+ | ==== Operation on bool / null ==== | ||
+ | |||
+ | <code php> | ||
+ | // booleans | ||
+ | $a = false; | ||
+ | ++$a; // int(1) + warning | ||
+ | ++$a; // int(2) | ||
+ | $a = true; | ||
+ | --$a; // int(0) + warning | ||
+ | --$a; // int(-1) | ||
+ | |||
+ | // null values | ||
+ | $a = null; --$a; // int(-1) + warning | ||
+ | $a = null; ++$a; // int(1) + warning | ||
+ | </ | ||
+ | |||
+ | ==== Operation on alphanumeric strings ==== | ||
+ | |||
+ | <code php> | ||
+ | // non-numeric strings | ||
+ | $a = ' | ||
+ | ++$a; // string(4) " | ||
+ | ++$a; // float(13) | ||
+ | </ | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== Backward Incompatible Changes ===== | ||
+ | |||
+ | Incrementing '' | ||
+ | |||
+ | ===== Proposed PHP Version(s) ===== | ||
+ | |||
+ | **PHP 7** | ||
+ | |||
+ | ===== 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