Re: [PROPOSAL] Alphanumeric decrement

From: Date: Fri, 13 Dec 2013 08:15:07 +0000
Subject: Re: [PROPOSAL] Alphanumeric decrement
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70619@lists.php.net to get a copy of this message
Hi, On Fri, Dec 13, 2013 at 3:09 PM, Kris Craig <kris.craig@gmail.com> wrote: > On Thu, Dec 12, 2013 at 9:58 PM, Marc Bennewitz <php@marc-bennewitz.de > >wrote: > > > Hi > > > > Decrementing "a" to a number isn't a good idea because on incrementing > > again you will increment the number and not go back to "a". > > > > Why not just have "a" decrement to an empty string (i.e. "") and an empty > string increment to "a"? Imagine a scenario in which an empty posted value is assumed to be a number and so ++$x is applied; instead of getting the expected "1" they now get "a" which, after an (int) cast will become 0 .. surprise! Then a decrement on an empty string could trigger > a warning and remain empty. That way, we won't have situations where > decrementing from "a" and incrementing back would output a number. > Actually, the increment of "" is "1", which is still a string; the increment of "1" is int(2), though. That said, isn't it bad enough that php already has exceptions such as: * ++$x is not always the same as $x += 1 * ++false remains false, but ++null becomes int(1) If decrementing strings should work, I would request to also make ++false => true and --true => false Lastly, if I could go back in time I would have created str_inc() and str_dec() so that + has a unambiguous meaning :) > > --Kris > -- -- Tjerk

« previous php.internals (#70619) next »