5

I am calling a method using SOAPclient and the method (remote external SOAP web service) is returning me a 19 digit number. I have no control over what is being returned. When i print the value of this number only the first 16 digits are accurate. I have tried type casting, GMP etc. But looks like the full 19 digits is already lost when php assigns the value to the variable based on the result from the web service call. So there is no way to retrieve the value.

$client = new SoapClient($sccSystemWSDL);
try{
    $sessionID = $client->logonUser($adminUser,$passWord);
}

On a 64 bit machine I did not have this issue. But now I have to run this on a 32 bit machine and no luck till now.

Kerem
  • 11,377
  • 5
  • 59
  • 58

2 Answers2

5

Use BCMath it allows the numbers to be processed as strings instead of integers so does not have size limit. Also you should increase the precision directive to a larger number say 20 or so.

kittycat
  • 14,983
  • 9
  • 55
  • 80
  • 1
    + On the Precision directive but also note that precision can have some funny effect on BCMath when dealing with floating point see http://stackoverflow.com/a/14656315/1226894 – Baba Feb 26 '13 at 13:02
1

Cryptic's answer of using BCMath is good. Alternatively, you can use phpseclib's BigInteger class that is a wrapper around BCMath and GMP, and also has a custom PHP fallback.

The problem you are experiencing exists because PHP has no built-in support for integers that exceed the maximum integer value of the system it runs on. Instead, it is limited to what the operating system supports. For 32-bit systems this means the maximum integer value is 2^31, and on 64-bit systems this value is 2^63 (save one bit to sign the value, e.g. indicate whether it is positive or negative).

Xano
  • 62
  • 5