I know PHP does not support unsigned 64 bit integers.
However I simply need to read unsigned 64 bit integer values from a MySQL table via PDO query, and pass them through to clients (without performing any calculation or comparison); the PHP page is publishing a very simple REST interface to clients and should output the query result as JSON data only.
Right now the PDO query returns untouched integers as long as they are 63bit wide (no sign), but when the original value in the table has the 64th bit set, the PDO driver converts it to a string (I have set PDO::ATTR_STRINGIFY_FETCHES
attribute to false, since I want types to be preserved as much as possible).
When I call the json_encode()
function, the related fields get the same treatment: they become strings when they exceed 63 bit width.
I do not want to leave them as strings in json output, since it would require "breaking" changes in client code to have them handling json-string to ulong conversion upon decoding.
Is there a way to customize json_encode behavior somehow to output them as "UInt64" ?
I've taken a look at JsonSerializable but it seems it cannot solve my issue.