Take the State of PHP 2026 Survey →

Alphanumeric Decrement View as Markdown

Declined
Authors
Andrea Faulds ajf@ajf.me
Date
2013-12-16
Version
1.0
Source
wiki.php.net/rfc/alpanumeric_decrement

Vote

Alphanumeric Decrement closed
Yes
0
No
21
21 voters
ajf No 2014-01-22 11:52
chobieeee No 2014-01-22 07:32
datibbaw No 2014-01-21 00:25
daverandom No 2014-01-21 16:54
derick No 2014-01-21 20:57
dm No 2014-01-21 16:59
dmitry No 2014-01-23 07:57
dsp No 2014-01-21 15:06
krakjoe No 2014-01-21 07:36
laruence No 2014-01-21 03:20
levim No 2014-01-21 23:26
lstrojny No 2014-01-21 20:46
malukenho No 2014-01-27 11:44
peehaa No 2014-01-22 09:38
philstu No 2014-01-21 20:34
pollita No 2014-01-24 10:12
shm No 2014-01-22 12:51
stas No 2014-01-21 00:25
treffynnon No 2014-01-22 13:08
tyrael No 2014-01-22 13:23
willfitch No 2014-01-21 14:09

Discussions on the mailing list

[VOTE] [RFC] Alphanumeric Decrement
by Andrea Faulds · 19 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:53 UTC

Introduction

This will add support for decrementing alphanumeric strings (“ab”, for example) to complement the existing incrementing behaviour.

Proposal

At present, incrementing alphanumeric strings is supported. For example:

$x = "z";
$x++;
// $x is now "aa"

However, decrementing alphanumeric strings is not:

$x = "z";
$x--;
// $x is still "z"

Under this proposal, alphanumeric strings would be decrementable:

$x = "z";
$x--;
// $x is now "y"

It would also handle the edge case of decrementing from “a”, choosing to result in 0 (this may be subject to change):

$x = "a";
$x--;
// $x is now 0

The patch at present additionally changes how empty strings are incremented. At present, it works as follows:

$x = "";
$x++;
// $x is now "1" (string)
$x = "";
$x--;
// $x is now -1 (int)

With this patch, it is now consistent:

$x = "";
$x--;
// $x is now "-1" (string)

Backward Incompatible Changes

This might arguably be a BC break, as now decrementing for these strings would work, while existing code might assume that doesn't work. I doubt there is any code relying on that though, especially since “a”++ is a relatively obscure feature.

Proposed PHP Version(s)

Next PHP 5.x. Failing that, next PHP x.

SAPIs Impacted

None.

Impact to Existing Extensions

None.

New Constants

None.

php.ini Defaults

None.

Open Issues

How should decrementing “a” be handled? The patch and behaviour as proposed decrement to 0, however possibly not decrementing and emitting a warning might make more sense.

Unaffected PHP Functionality

Does not affect $x += 1 and $x -= 1, nor $x = $x + 1 and $x = $x - 1, as both of these do not support alphanumeric increment at present.

Future Scope

In future, alphanumeric increment being supported $x += 1 and $x = $x + 1 might be desirable, but that is not within the scope of this RFC.

Vote

Merge into PHP 5.6? (Will assume this requires 2/3 majority, due to new language feature)

Voting started 2014-01-21 and ended 2014-01-28.

Vote: Alphanumeric Decrement — Yes: 0 · No: 21 (closed)

Patches and Tests

https://github.com/php/php-src/pull/546

Considered final patch, unless bugs are found.

Implementation

Not merged in at present.

References

Mailing list discussion: http://marc.info/?l=php-internals&m=138687859827708&w=1

Rejected Features

None as yet?