Hi Andrea,
On Fri, Dec 13, 2013 at 5:02 AM, Andrea Faulds <ajf@ajf.me> wrote:
> At present, it's possible to increment (++) an alphanumeric string, such
> that "a" when incremented becomes "b", "z" becomes
> "aa", and so on.
>
> However, it's irritated me that the same is not true for the decrement
> (--) operator. At present, "aa" when decremented stays as "aa", and
> "b"
> when decremented stays as "b". This lack of symettry is counterintuitive to
> me. I don't think it's what you would expect here.
>
> So I've written a patch which would change this. "aa" when decremented
> would be "z", and "b" when decremented would be "a". It also
> handles
> decrementing "a", which becomes "0". This creates an interesting new
> asymettry: {$a = "a"; $a--; $a++;} will result in $a being integer 1. I
> think it's better than the previous behaviour, though, which resulted in
> "b".
>
> The diff is here: https://github.com/TazeTSchnitzel/php-src/
> compare/php:PHP-5.6...AlphanumericDecrement
>
> My aim is to try and get this into PHP 5.6, if people are interested.
> Thoughts?
>
Your proposal would be more intuitive than the current behavior
in most cases.
While a go, I was about to propose similar patch, but I didn't.
I think the reason was that I've concluded it is impossible to
make string decrements logical anyway.
Just my .02c
I'll read your patch and may comment if there is something to say.
There are users who use string increment now, but I suppose nobody
is using string decrements because it's not working as most people
expect. Edge case should be considered carefully, since it would
cause more confusion than now.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net