Feature Proposal: Allow letter decrementing
| From: | Chris London | Date: | Thu, 18 Jul 2013 13:46:14 +0000 |
| Subject: | Feature Proposal: Allow letter decrementing | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-68160@lists.php.net to get a copy of this message | ||
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