Re: Feature Proposal: Allow letter decrementing
| From: | Yasuo Ohgaki | Date: | Fri, 19 Jul 2013 07:08:11 +0000 |
| Subject: | Re: Feature Proposal: Allow letter decrementing | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-68183@lists.php.net to get a copy of this message | ||
Hi,
2013/7/19 Mateusz Kocielski <shm@digitalsun.pl>
> > see
> > http://www.php.net/manual/en/language.operators.increment.php
>
> I don't see any explanation for the examples above. Documentation says:
>
> [...] For example, in PHP and Perl $a = 'Z'; $a++; turns $a into 'AA' [...]
>
> I'd expect " ZZ" to become " AAA" rather than " AA".
> I'm not sure if
> it's a bug in documentation, in code. Probably nobody can even
> distinguish if it's a bug or feature.
>
You may play with one liner.
php -r "\$a = ' ZZ';for (\$i=0; \$i<100000000;\$i++) var_dump(++\$a);"
This feature existed when I start using PHP3.
Manual says
> Note that character variables can be incremented but not decremented and
> even so only plain ASCII characters (a-z and A-Z) are supported.
Incrementing/decrementing
> other character variables has no effect, the original string is unchanged.
This behavior is due to the algorithm used for string ++/--.
I think it looks at the end of char and tries to increment, but it
finds non [a-zA-Z] char and stops operation. Therefore, it cycles
over and over.
It may seems strange, but I don't see reason to change.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net