socket.io-php-emitter
socket.io-php-emitter copied to clipboard
Message pack improperly serializes maps with numerical indexes
When emitting a map of data that uses non-sequential numerical indexes, e.g.:
$data = [
"3" => "foo",
"7" => "bar"
];
$emitter = new SocketIO\Emitter();
$emitter->emit('event', $data);
The data is serialized, emitted, and received as an array, e.g.:
{
"0": "foo",
"1": "bar"
}
The only way around this right now is to add a non-numerical key into the map, e.g.:
$data = [
"3" => "foo",
"7" => "bar",
"hack" => true
];
$emitter->emit('event', $data);
The reason this is happening is because in this file (https://github.com/rase-/socket.io-php-emitter/blob/master/src/msgpack_pack.php#L79) starting at line 79, the code is converting the data to an array if all keys in the data are ints, regardless of if the keys are sequential or not.