Ninjakreborn Posted April 18, 2006 Share Posted April 18, 2006 I have a question about typecasting, forcing a variable to have a specific type.should I get in the habit of typecasting every single variable I create in working with php to what I want it to be no matter what, or is there a bad reason for doing this. I was thinking of every single time I create a variable, I should typecast it, or is that going to make it hard to change variables on teh fly when I decide to change them some as I go, basically either way when are the best reasons, or purposes where typecasting should be used. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 18, 2006 Share Posted April 18, 2006 The need to typecast in PHP is rare as most of the time the processor will do it for you depending on the context in which the variable is used.The only occasion I can think of immediately is when rounding results of a division.If you want to show how many pages of results there are and want to have a whole number (int) instead of a float[code]$total_records = 25;$recs_per_page = 10;$pages = (int) ceil ($total_records / $recs_per_page); [/code] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 18, 2006 Author Share Posted April 18, 2006 thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.