# [rfc] normalize increment and decrement operators

- Thread: https://staging.externals.io/message/72621
- Original archive: https://news-web.php.net/php.internals/72621
- Started by Tjerk Meesters on 2014-02-15T02:12:19+00:00
- Messages: 2
- RFC: Normalizing increment and decrement operators (Inactive) — https://staging.externals.io/rfc/normalize_inc_dec.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #72621 — Tjerk Meesters — 2014-02-15T02:12:19+00:00

URL: https://staging.externals.io/message/72621#72621

Hi all,

Following the earlier discussion of adding decrement for strings to
complement the existing alphanumeric increment feature, I've written a
proposal to normalize the behaviour across boolean and null values.

https://wiki.php.net/rfc/normalize_inc_dec

Based on some earlier comments, boolean and null values can be treated in
two distinct way, both of which are demonstrated in the rfc; I'm hoping
that before voting takes place we can eliminate one voting option
altogether.

It also aims to deprecate string-based increments using `++`; instead, it
would introduce `str_inc()` and `str_dec()` as a regular function.

Let me know your thoughts.


-- 
--
Tjerk

---

## #72622 — Andrea Faulds — 2014-02-15T02:26:51+00:00

URL: https://staging.externals.io/message/72621#72622 · In reply to: #72621

> Following the earlier discussion of adding decrement for strings to
> complement the existing alphanumeric increment feature, I've written a
> proposal to normalize the behaviour across boolean and null values.
>
> https://wiki.php.net/rfc/normalize_inc_dec
>
> Based on some earlier comments, boolean and null values can be treated in
> two distinct way, both of which are demonstrated in the rfc; I'm hoping
> that before voting takes place we can eliminate one voting option
> altogether.
>
> It also aims to deprecate string-based increments using `++`; instead, it
> would introduce `str_inc()` and `str_dec()` as a regular function.
>
> Let me know your thoughts.

I actually already wrote a patch for removing alphanumeric increment and 
decrement, if you're interested: 
https://github.com/TazeTSchnitzel/php-src/tree/AlphanumericIncrement

Personally, I think the sanest solution is to increment number-looking 
strings as if they were numbers ("0" becomes 1), increment numbers 
(obviously), and throw a warning and do nothing for everything else.

Though it would be best if the $a++ behaviour matches $a += 1 and $a = 
$a + 1. So, while I'd prefer the strict approach I just mentioned, we 
should actually make it function identically to the other ways of 
incrementing.

-- 
Andrea Faulds
http://ajf.me/
