5 ms·
It seems to me that the issue is that $i++ is nonsensical if $i is a string (and $i is a string, not a character). But instead of raising an error, PHP soldiers
by alextgordon 16y ago
It seems to me that the issue is that $i++ is nonsensical if $i is a string (and $i is a string, not a character). But instead of raising an error, PHP soldiers on and tries to apply some completely unexpected function.
- nostrademons 16y agoIt's actually occasionally useful if you're trying to gensym a string. In a normal language, you need to write your own gensym function - in PHP, you know that $s++ will create a sequence of unique strings, suitable for use in b64-only environments, that will never run out.
- photon_off 16y agoPerl does this, too. And is it really that unexpected? How many possible things could 'z'+1 return? The only possibilities that make sense to me are "{", "aa", or an error. I like PHP because it's flexible, and this often makes life easier. If you're really going to try to use strings as integers, then you deserve what's coming to you. If you're going to use this behavior as a feature, then you've just saved yourself a chunk of time.
- pbhjpbhj 16y ago>How many possible things could 'z'+1 return? That are less than or equal to z?
- loewenskind 16y agoMore sensible would be to not overload the ++ or +1 operator to do this but provide a different function. Then the capability is there but something unexpected doesn't happen in the presence of type errors.
- jeffffff 16y agoi would certainly expect it to go through the charset in order instead of jumping back to a, but if you think of a string as a base 256 (or 26 in this case) number then it makes sense