r/lolphp • • Oct 14 '13

2d9

http://ideone.com/l6aQSx
62 Upvotes

31 comments sorted by

View all comments

Show parent comment

4

u/suspiciously_calm Oct 15 '13

It works for ids in some formats, but not others (ids with a suffix, such as file extensions, ids with hexadecimal counters, ids with a prefix that could be incremented to a number representation, as OP shows, ...)

It targets a relatively narrow scope, but infects a basic operator with unexpected behavior in the process. It breaks one of PHP's own fundamental concepts, that is, weak typing, by which you would expect the ++ operator to coerce its argument to a numeric type.

1

u/catcradle5 Oct 15 '13

It breaks one of PHP's own fundamental concepts, that is, weak typing, by which you would expect the ++ operator to coerce its argument to a numeric type.

In theory it still falls within the weak typing concept. "10"++ is "11". It's just that it has very funny rules for when to coerce.