I was wondering what is the best way to typecast a value from one type to another.
Which variant should we use:
intval($value);
It can depend on what types you're converting. PHP is already designed to convert types on-the-fly. It can convert the string '5' into the integer value 5 or float 5.0 if necessary. That's just PHP's natural type converting, but there are ways to force similar behaviours.
In many cases intval() can actually be faster than (int) typecasting, especially in string-to-integer converting. But personally, as I also write C++, I use typecasting as it is more natural and neat to me. The results, however, vary slightly in different situations. I never thought of settype() to be promising, though.