while reading scripts i downloaded here, i noticed that most of the users use *val() (intval,strval,...) funtions to typecast a variable. Well I just wanted to tell them that calling functions in php can slow down your script execution, especially when you can use built-in (int), (string), (bool), and other statements (i dont know how they are called). When casting int type with (int) o a string var it was done 40% faster than using intval() function. But I read that in some cases it can reach up to 350%. So for the sake of your scripts dont use functions to typecast.
about typecasting and script optimization
Collapse
X
-
about typecasting and script optimization
Progress:PHP Code:$("#mfreak").find(".head brain").clone();
Output:Code:[|||___________________________] : 5%
Support answer:Code:Memory limit reached, unable to complete operation.
Code:Try using a super uber strong mega computer to reach at least 10%.
Tags: None
-
you can still use (int) even in if statements. The point is that its faster, and it does the same work.Originally posted by arnage View PostDepending.
For examle, when/if is needed, the same value can be float and int so can't define both at 4 and 4.4 but intval() is ok with both values.
Progress:PHP Code:$("#mfreak").find(".head brain").clone();
Output:Code:[|||___________________________] : 5%
Support answer:Code:Memory limit reached, unable to complete operation.
Code:Try using a super uber strong mega computer to reach at least 10%.

Comment
-
oh, you were thinking about the intvals second param, base conversion.yup i know now what were you thinking with that float, sorry i was a bit confused earlier. Well that issue is beyond reach of my thread. I just wanted to tell some coders here how to optimize scripts, as i saw many use intval to convert strings to ints(mostly when fetcing ids from get), and its faster with (int)Originally posted by arnage View PostI didn't mention if() anywhere.
(int) is int, for example 4, (float) is float, for example 4.4, and intval() is both. So it doesn't do the same thing. Also intval() is commonly used for conversion, not just expected values like (int). 
.
Progress:PHP Code:$("#mfreak").find(".head brain").clone();
Output:Code:[|||___________________________] : 5%
Support answer:Code:Memory limit reached, unable to complete operation.
Code:Try using a super uber strong mega computer to reach at least 10%.

Comment
-
You are right, it is one of cases when intval shouldn't be used insted int, simply because if "something unusual" is pased via url intval will convert it but int will set it to 0.
Meybe to be intval() used with abs()... But here would be your question of speed.
Last edited by arnage; 18.08.12, 09:59.<!DOCTYPE html PUBLIC "-//WAPFORUM.RS
Comment
Comment