[UPHPU] Understanding php's logic
davidsmith at byu.net
Wed Apr 7 07:08:59 MDT 2004
Jacob Fugal wrote:
> I agree it seems a rather strange interpretation of ++ on strings, and
> I don't know where it's documented. I may not even be right, this just
> seems the most logical interpretation of the evidence he presented.
> And in a weird sort of way, it does make sense -- though not as much
> sense as "Z"++ = "[".
I think it makes perfect sense. In C, you cannot do "Z"+1, but you can
do 'Z'+1 (single quotes), which interprets the Z as its ASCII value.
There is no C comparison for "Z"+1, since "Z" is a string (char* in C).
I guess if you did this in C, you would actually be doing pointer
char *letter = "A";
int i = 0;
for( i=0; letter <= 'Z', letter++ )
printf( "%s\n", letter );
And that's likely not the intended behavior. :)
PHP has simply decided to handle string and the + operator that way. I
like it, though I would never use it in a real application as I think it
is error prone and difficult to read. :-)
More information about the UPHPU