# PHP ignoring typecast through class



## aximbigfan (May 8, 2008)

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


----------



## CrackerJack (May 8, 2008)

aximbigfan said:


> 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.
> 
> ...



pm me


----------



## aximbigfan (May 8, 2008)

You got mail.

Thanks!

Chris


----------



## Kreij (May 8, 2008)

While Pm'ing is great, people cannot see the solution to your problem.
Please post the solution here when you resolve the problem.


----------



## aximbigfan (May 8, 2008)

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


----------



## Kreij (May 8, 2008)

CAn you post a little code, so we can see what you are trying to do?


----------



## panchoman (May 8, 2008)

do you have updated php with all functions avaliable and all like xeon and stuff like that.


----------



## Oliver_FF (May 9, 2008)

As far as I know PHP is a loosely typed language in that there is only one data type, "var"...


----------



## ZenZimZaliben (May 21, 2008)

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";
?>


----------

