In the cases that you mentioned, there is no serious reason indeed . This is due not only to the fact that PHP is a dynamically typed language, and the operators used are not type sensitive.
However, casting has many good uses. In the case of (int) you can use to ensure that you always use an integer during operations. In addition, by keeping ahead of time you save PHP from having to constantly introduce juggling later.
Edit due to editing question (rev4)
The last two points are due to the fact that PHP will try to force a string into an integer during a mathematical operation. Thus, it parses the string as a number. As soon as he cannot find a real integer, the found number is returned.
Basically, from the beginning of the line, find everything that matches the integer / floating format . Once something STOPS conforms to this format, return what you have. If the first character cannot match the format, return 0; .
For a better explanation, see: http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting
Kevin peno
source share