rfc:normalize_inc_dec

This is an old revision of the document!


PHP RFC: Your Title Here

Introduction

This proposal aims to make the current behaviour more intuitive:

// booleans
$a = false; ++$a; // bool(false)
$a = true; --$a; // bool(true)
 
// null values
$a = null; --$a; // null
 
// empty strings
$a = ''; ++$a; // string(1) "1"
 
// non-numeric strings
$a = '12d9'; 
++$a; // string(4) "12e0"
++$a; // float(13)

For strings, it makes two new functions available:

  • str_inc($str) - to perform the current string increments.
  • str_dec($str) - the string decrement.

Proposal

The following behaviour is being proposed:

// booleans
$a = false; ++$a; // int(1)
$a = true; --$a; // int(0)
 
// null values
$a = null; --$a; // int(-1)
 
// empty strings
$a = ''; ++$a; // int(1)
 
// non-numeric strings
$a = '12d9'; 
++$a; // string(4) "12e0" + Notice: String increment is deprecated, use str_inc() instead in php shell code on line 1
++$a; // float(13)

Backward Incompatible Changes

None, since incrementing boolean and null values wasn't possible in the first place.

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:

  • array
  • int
  • float
  • object
  • resource

Proposed Voting Choices

Yay or nay.

Patches and Tests

Coming soon ...

Implementation

N/A

References

Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/normalize_inc_dec.1387447333.txt.gz · Last modified: 2017/09/22 13:28 (external edit)