I have a collegue who constantly assigns variable and forces their type. For example he would declare something like so:
$this->id = (int)$this->getId();
or when returning he will always return values as such:
return (int)$id;
I understand that php is a loosely typed language and so i am not asking what the casting is doing. I am really wondering what the benefits are of doing this – if any – or if he is just wasting time and effort in doing this?
There are a few benefits.