views:

1284

answers:

4

We have a customer that is trying to call our web service written in C# from PHP code. The web service call takes a long as parameter.

This call works fine for other customers calling from C# or Java but this customer is getting an error back from the call. I haven't debugged their specific call but I am guessing that the 64bit integer is getting truncated somehow from PHP. The customer says they are just making the web service call with a string but is there a wrapper in PHP that does type conversion. Could this be losing the number information?

Thanks for any info.

+1  A: 

Most PHP installations won't support 64 bit integers - 32 is the max. You can check this by reading the PHP_INT_SIZE constant (4 = 32bit, 8 = 64bit) or read the PHP_INT_MAX value.

<?php

echo PHP_INT_SIZE, "\n", PHP_INT_MAX;

?>

If the web service class he is using is trying to type-convert a string representation of a 64 bit integer, then yes, it's mostly likely being truncated or converted into a float. You can sort of see this behavior with this simple test

<?php

echo intval( "12345678901234567890" );
// prints 2147483647, the max value for a 32 bit signed int.

Without knowing the details of his implementation, it's difficult to postulate on what a good solution/workaround might be.

Peter Bailey
A: 

If you absolutely must take a big number like that, make it a string, and convert it to long in your web service.

This will bother your other users a little bit, but would make it more friendly to your PHP-using costumers.

Francisco Soto
A: 

PHP brutally murdered its integer support, to the point where you have no predictable way of knowing it a specific install will handle 32-bit or 64-bit integers.

The easiest way to handle this would be to expose a new endpoint that takes a string, and just cast it on your end.

For reference on PHP's epic fail:

http://www.mysqlperformanceblog.com/2007/03/27/integers-in-php-running-with-scissors-and-portability/

FlySwat
A: 

I wrote an article regarding PHP using nuSoap to call a C# web service... Haven't yet encountered the issue with long int conversions, but I will definately be running some tests to see if I should add it into my article. Thanks, Sean http://seanmcilvenna.com/blog/7-general/24-windows-php-development