I was reading some code that a consultant provided us. It’s a bit convoluted, and at the end of a function, it reads:
return (int) 1;
Instead of:
return 1;
PHP has a lot of magic in it; is this as bone-headed as it looks, or is there a valid reason to cast an integer as an integer?
No, it’s the same.
1is an integer literal.See here these are all integer literals; casting to
inthas no effect:If you did
return "1";that would be an entirely different matter. There are some differences in behaviour between"1"(string) and1(int), namely with bitwise operators.