_______________________________
Printable View
_______________________________
They both do essentially the same thing. They are both language constructs and both are used to cast a variable type explicitly.
I cannot confirm but it would make sense to assume that using the direct cast (string) is better performance wise. When you use settype the intepreter needs to evaluate the string in the second argument before carrying out the cast.
If the type argument for settype is a variable, then the interpreter also needs to lookup the variable in memory as the value may have changed since it was first defined. Using (string), the cast can be applied in a single operation and that operation hard coded when the script is parsed by the interpreter.
In summary, if you know the type of the variable before the script is run then it is better to use (string). If you will be determining the type during the execution of the script then you are better off using settype.
settype will change the type of the variable; casting only affects the result of the expression.
I knew that :p :cry:
thanks both. Resolved. ;)
Regards.