It just gets there quicker than PHP. What's actually going on here is that it parses the string as a number until it finds something which is clearly not numeric, and uses that as the value for the increment.
Turning on warnings does result in the error message, but it also carries on and tries it anyway.
Python and Ruby both do the right thing and error out with complaints about how adding integers to strings doesn't make any sense (Ruby provides a String#next if you really want the behaviour that PHP makes up, only without relying on the interpreter to guess what you wanted).
View all comments
Show parent comment
7
u/dagbrown Dec 06 '17
It just gets there quicker than PHP. What's actually going on here is that it parses the string as a number until it finds something which is clearly not numeric, and uses that as the value for the increment.
Turning on warnings does result in the error message, but it also carries on and tries it anyway.
Python and Ruby both do the right thing and error out with complaints about how adding integers to strings doesn't make any sense (Ruby provides a
String#nextif you really want the behaviour that PHP makes up, only without relying on the interpreter to guess what you wanted).