[UPHPU] Understanding php's logic

emails at boucha.us emails at boucha.us
Thu Apr 8 18:13:37 MDT 2004

"Z"++=="AA" does make sense to me. This seems to be very common. Take for
example a spreadsheet program, if you create a whole bunch of columns, the
column after Z  is AA. Go try it in Excel.

> Today at 7:08am, David Smith said:
>>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
>> arithemtic:
>>#include <stdio>
>>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. :-)
> If I'm understanding you right, it sounds like you're saying that PHP is
> interpreting "string"++ as pointer arithmetic. While that makes perfect
> sense in C, in PHP it makes no sense at all to me, especially since
> "A"++=="B", "B"++=="C", etc. The one that I can't fathom or explain is
> how "Z"++=="AA". That can't be pointer arithmetic...
> I actually checked about a character literal (like C's 'A' syntax) in
> PHP but it turns out there are no character literals, only strings.
> While there are a thousand workarounds, the fact that this "mostly"
> works, and the strange ways in which it doesn't, are still bugging me.
> Mac
> --
> Mac Newbold		MNE - Mac Newbold Enterprises, LLC
> mac at macnewbold.com	http://www.macnewbold.com/
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: list-unsubscribe at uphpu.org
> For additional commands, e-mail: list-help at uphpu.org

More information about the UPHPU mailing list