If you’re using the GoCardless PHP library with PHP 7.1 or later, you may see an error saying that "One of your parameters was incorrectly typed” when trying to send numbers to the API (for example, specifying an amount when you create a payment).
This will only happen if you’ve customised PHP’s serialize_precision
option, changing it from its default value of -1
.
PHP 7.1 changes the behaviour of json_encode
so that it uses this option to decide how to output numbers in JSON.
When the option is set to the default, -1
, PHP does some clever rounding, but with other values, you’ll end up with too many decimal places getting sent to the API (for example the number 3509.00 can confusingly get serialised as 3509.0000000000005 instead of 3509), making the data invalid.
There are two ways you can fix this issue:
- Reconfigure PHP’s
serialize_precision
option to-1
(you can do this in yourphp.ini
, or during runtime usingini_set
. This might cause problems if your code relies elsewhere on how numbers are serialised. - Make sure you pass numbers to the GoCardless PHP library as integers or strings.