Hi,

2013/7/19 Mateusz Kocielski <s...@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
yohg...@ohgaki.net

Reply via email to