|
-
Nov 29th, 2008, 06:59 AM
#1
Thread Starter
Lively Member
_______________________________
_______________________________
Last edited by Y.P.Y; Apr 28th, 2012 at 05:16 PM.
-
Nov 29th, 2008, 12:12 PM
#2
Re: settype($X, 'string') V.S. (string)$X
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.
-
Nov 30th, 2008, 09:10 PM
#3
Re: settype($X, 'string') V.S. (string)$X
settype will change the type of the variable; casting only affects the result of the expression.
-
Dec 1st, 2008, 08:18 AM
#4
Re: settype($X, 'string') V.S. (string)$X
I knew that
-
Dec 1st, 2008, 08:25 AM
#5
Thread Starter
Lively Member
Re: [RESOLVED] settype($X, 'string') V.S. (string)$X
thanks both. Resolved. 
Regards.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|