Results 1 to 5 of 5

Thread: [RESOLVED] settype($X, 'string') V.S. (string)$X

  1. #1

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Resolved _______________________________

    _______________________________
    Last edited by Y.P.Y; Apr 28th, 2012 at 05:16 PM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: settype($X, 'string') V.S. (string)$X

    settype will change the type of the variable; casting only affects the result of the expression.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: settype($X, 'string') V.S. (string)$X

    I knew that
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    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
  •  



Click Here to Expand Forum to Full Width