Re: [PROPOSAL] Alphanumeric decrement

From: Date: Fri, 13 Dec 2013 10:02:20 +0000
Subject: Re: [PROPOSAL] Alphanumeric decrement
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-70622@lists.php.net to get a copy of this message
On Thu, Dec 12, 2013 at 9:02 PM, Andrea Faulds <ajf@ajf.me> wrote: > Good evening, > > 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? > > -- > Andrea Faulds > http://ajf.me/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Hi, While I agree that the current implementation is unintuitive, I would be against changing it in a minor version. In this thread multiple people mentioned that it would be ok to change the alpha decrementing, because it wasn't working before and/or nobody would use it as it isn't working currently. I think you misuse the "not working" here. It works (as it doesn't throw an error), but it behaves differently, what you would like/expect to see, and we also have this behavior documented. So changing the behavior in my opinion would be a BC break, and given the nature of this feature, I think that there are no solution, which would eliminate all the edge-cases and make the feature truly consistant/symetric to the current incrementing and to our type juggling, so I think we can't even call it a bugfix(and ship it in a minor), when we change it from mostly-broken to slightly-broken. -- Ferenc Kovács @Tyr43l - http://tyrael.hu

« previous php.internals (#70622) next »