Just a quickie... Im a bit confused by this piece of code...

Discussion in 'PHP' started by relixx, Oct 11, 2006.

  1. #1
    I'm currently trying to figure out a huge mess of undocumented spaghetti code and Im just wondering what

    $variable=(int)$variable
    PHP:
    means. does (int) convert $variable to an integer? I'm seeing it a lot of $variable=(int)$variable in this mess of coding and I can't seem to figure out what it means ($variable being a generic name, naturally. The variable names range from resto to idffxchp *sighs*)
     
    relixx, Oct 11, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes. Just in case $variable was 2.11 it now becomes 2. Just cuts it to an integer as you guessed.
     
    T0PS3O, Oct 11, 2006 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just to add to T0PS3O's comments: sometimes this is used as a poorman's data scrubber for SQL commands.

    If that variable was passed in by the user somehow and it's going to be used in an SQL command as an integer, that command will make sure that they're not passing in any form of SQL injection...
     
    TwistMyArm, Oct 11, 2006 IP
  4. relixx

    relixx Active Member

    Messages:
    946
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    70
    #4
    Ah, ok, that explains a lot with this section of the script actually, thanks :)
     
    relixx, Oct 11, 2006 IP