Explicit and implict casting
PHP automatically casts strings to integers when doing arithmetic. However, intval($string) and $string + 0 is not the same! The first one works on numbers only, as described under String conversion to numbers in the manual, however, the latter is happy to accept numeric strings which again means that hexadecimal numbers are accepted. Compare print "0xf"+0 to intval("0xf").

Comments
Post new comment