1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

PHP ignoring typecast through class

Discussion in 'Programming & Webmastering' started by aximbigfan, May 8, 2008.

  1. aximbigfan New Member

    Joined:
    Oct 15, 2006
    Messages:
    847 (0.22/day)
    Thanks Received:
    35
    Location:
    St. Louis, MO
    I have a code layout with a class. In that class is a function that must return either a string or an integer. The problem is that even when (int) is used in front of the variable to return, the return is ALWAYS a string.

    Any ideas? The function works just fine on i's own.

    Thanks,
    Chris
     
    10 Year Member at TPU
  2. CrackerJack

    Joined:
    Dec 13, 2007
    Messages:
    2,758 (0.81/day)
    Thanks Received:
    470
    pm me
     
  3. aximbigfan New Member

    Joined:
    Oct 15, 2006
    Messages:
    847 (0.22/day)
    Thanks Received:
    35
    Location:
    St. Louis, MO
    You got mail.

    Thanks!

    Chris
     
    10 Year Member at TPU
  4. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,826 (3.74/day)
    Thanks Received:
    5,631
    Location:
    Cheeseland (Wisconsin, USA)
    While Pm'ing is great, people cannot see the solution to your problem.
    Please post the solution here when you resolve the problem.
     
    10 Year Member at TPU
  5. aximbigfan New Member

    Joined:
    Oct 15, 2006
    Messages:
    847 (0.22/day)
    Thanks Received:
    35
    Location:
    St. Louis, MO
    There was no solution. He tried, but we couldn't solve it.

    Unless someone can figure out whats going on here, I'll assume it is a bug in PHP and needs to be reported.

    Chris
     
    10 Year Member at TPU
  6. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,826 (3.74/day)
    Thanks Received:
    5,631
    Location:
    Cheeseland (Wisconsin, USA)
    CAn you post a little code, so we can see what you are trying to do?
     
    10 Year Member at TPU
  7. panchoman

    panchoman Sold my stars!

    Joined:
    Jul 16, 2007
    Messages:
    9,595 (2.71/day)
    Thanks Received:
    1,201
    do you have updated php with all functions avaliable and all like xeon and stuff like that.
     
  8. Oliver_FF

    Oliver_FF New Member

    Joined:
    Oct 15, 2006
    Messages:
    544 (0.14/day)
    Thanks Received:
    65
    As far as I know PHP is a loosely typed language in that there is only one data type, "var"...
     
    10 Year Member at TPU
  9. ZenZimZaliben

    ZenZimZaliben

    Joined:
    Mar 4, 2005
    Messages:
    3,002 (0.68/day)
    Thanks Received:
    765
    There are many data types. $str $int $vchar ....ie.

    The question is this class file pulling from a database? It could be that the database field is setup to be a string.

    Either way something as simple as this can do string to int conversion.
    <?php
    $str = "10";
    $num = (int)$str;
    if ($str === 10) echo "String";
    if ($num === 10) echo "Integer";
    ?>
     
    10 Year Member at TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)