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:
    848 (0.29/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
  2. CrackerJack

    CrackerJack

    Joined:
    Dec 13, 2007
    Messages:
    2,705 (1.10/day)
    Thanks Received:
    449
    Location:
    East TN
    pm me
  3. aximbigfan New Member

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

    Thanks!

    Chris
  4. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.02/day)
    Thanks Received:
    5,615
    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.
  5. aximbigfan New Member

    Joined:
    Oct 15, 2006
    Messages:
    848 (0.29/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
  6. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.02/day)
    Thanks Received:
    5,615
    Location:
    Cheeseland (Wisconsin, USA)
    CAn you post a little code, so we can see what you are trying to do?
  7. panchoman

    panchoman Sold my stars!

    Joined:
    Jul 16, 2007
    Messages:
    9,595 (3.68/day)
    Thanks Received:
    1,200
    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:
    546 (0.19/day)
    Thanks Received:
    65
    As far as I know PHP is a loosely typed language in that there is only one data type, "var"...
  9. ZenZimZaliben

    ZenZimZaliben

    Joined:
    Mar 4, 2005
    Messages:
    2,563 (0.74/day)
    Thanks Received:
    528
    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";
    ?>

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

Share This Page