[UPHPU] Understanding php's logic

David Smith DavidSmith at byu.net
Wed Apr 7 18:32:26 MDT 2004

<quote who="Mac Newbold">
> 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
>>#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.

No, you are not interpreting me right. I meant that PHP treats the +
operator special when on strings, and I was commenting on how different
the behavior is in C. In C, you get pointer arithmetic on a char*. In PHP,
you get an alphabetical increment.


More information about the UPHPU mailing list