Page 1 of 1

Can I enforce function parameter typing?

Posted: Tue Jul 29, 2008 3:00 am
by josamoto
I have the following function:

Code: Select all

<?php
function doSomething($withThis){
     // Do something $withThis 
     // ... for example - convert it to a string and echo it
}
?>
and I am calling it like this:

Code: Select all

<?php
doSomething(1234567890123456789012345678901234567890);
?>
PHP is interpreting the 1234567890... value as a double, meaning it displays as 1.2345678nnn+Exx when I convert it to a string. This is indeed the correct behaviour.

I want to convert the variable to a string and have PHP echo "1234567890123456789012345678901234567890", not scientific notation.

Oh, doSomething("1234567890...") with quotes is not an option, it has to be called without quotes if possible. You must be thinking: "Why in the hell is he trying to do that?"

Thanks for the help!

Re: Can I enforce function parameter typing?

Posted: Tue Jul 29, 2008 4:01 am
by deeessay
Try this:

function doSomething($withThis)
{
$convertedString = (string)$withThis;
return $convertedString;
}



<?php
echo doSomething(1234567890123456789012345678901234567890);
?>


hope this solves your problem...