rfc:normalize_inc_dec

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:normalize_inc_dec [2013/12/30 14:47] datibbawrfc: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 ====== ====== PHP RFC: Normalize increment and decrement operators ======
-  * Version: 0.1+  * Version: 0.2
   * Date: 2013-12-19   * Date: 2013-12-19
-  * Author:  +  * Author: Tjerk Meesters (datibbaw) 
-  * Status: Draft+  * Status: Inactive
   * First Published at: https://wiki.php.net/rfc/normalize_inc_dec   * First Published at: https://wiki.php.net/rfc/normalize_inc_dec
  
 ===== Introduction ===== ===== Introduction =====
  
-This proposal aims to make the current behaviour more intuitive:+The current behaviour of increment and decrement operators is not very intuitive:
  
 <code php> <code php>
Line 29: Line 29:
 </code> </code>
  
-For strings, it makes two new functions available:+===== Proposal =====
  
-  * ''str_inc($str)'' - to perform the current string increments. +The proposal is: 
-  * ''str_dec($str)'' - the string decrement.+  - always treat boolean and null types as an integer, but raise a warning. 
 +  - deprecate alphanumeric increment and introduce ''str_inc()'' and ''str_dec()''.
  
-===== Proposal ===== +==== Operation on bool / null ====
- +
-The following behaviour is being proposed:+
  
 <code php> <code php>
 // booleans // booleans
-$a = false; ++$a; // bool(true+$a = false;  
-$a = true; --$a; // bool(false)+++$a; // int(1) + warning 
 +++$a; // int(2
 +$a = true;  
 +--$a; // int(0) + warning 
 +--$a; // int(-1)
  
 // null values // null values
-$a = null; --$a; // null +$a = null; --$a; // int(-1) + warning 
-$a = null; ++$a; // null+$a = null; ++$a; // int(1) + warning 
 +</code>
  
-// empty strings +==== Operation on alphanumeric strings ====
-$a ''; ++$a; // int(1)+
  
 +<code php>
 // non-numeric strings // non-numeric strings
 $a = '12d9';  $a = '12d9'; 
Line 55: Line 59:
 ++$a; // float(13) ++$a; // float(13)
 </code> </code>
 +
 +Additionally, it makes two new string functions available:
 +
 +  * ''str_inc($str)'' - to perform the current string increments.
 +  * ''str_dec($str)'' - the string decrement.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-Null no longer decrements. Booleans couldn't be incremented in the first place, so there should be no breaks.+Incrementing ''null'' will now raise a warning; incrementing alphanumeric strings will raise a deprecation notice.
  
 ===== 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.1388414848.txt.gz · Last modified: 2017/09/22 13:28 (external edit)