On Thu, Jul 18, 2013 at 3:46 PM, Chris London <m...@chrislondon.co> wrote:
> My friend shared some code with me today that wasn't working for him. He > was incrementing letters like this: > > $letter = 'A'; > echo ++$letter; // Output: B > > He was then trying to decrement letters like this: > > $letter = 'B'; > echo --$letter; // Output: B > > He was really confused why his code wasn't working. Obviously the answer > is, PHP doesn't support decrementing letters. > > My question is, why specifically doesn't it? > > It seems logical that if we support increment we should support decrement. > > My proposal: > > 1) Support decrementing letters > - or - > 2) Throw a notice explaining that decrementing is not supported so > developers quickly know they can't do that > > One hiccup. I imagine maybe the reason we don't support decrementing is > because what would happen if you tried to decrement 'A'. In that case I > would suggest either returning NULL or throwing a notice. > > Thanks for the input > > Chris London > I don't think we should add string decrementing due to the rather complex logic behind it (imho the string incrementing that we have shouldn't be there either). What we *should* add though is a notice or warning in case an increment/decrement operation fails. incdec is one of the few places where we currently silently ignore FAILUREs, instead of throwing some helpful error message :) Nikita