msgpack-php icon indicating copy to clipboard operation
msgpack-php copied to clipboard

Throw exceptions when not possible to unpack

Open adanlobato opened this issue 11 years ago • 2 comments

We're attempting to include MsgPack as one possible serializer for our suite but we found the problem that when it is not possible to unpack data, msgpack_unpack triggers an error.

This is a big problem because in PHP it is not possible to capture a PHP error and act accordingly, so I propose two solutions:

  • Create a MessagePackException that is thrown whenever an error occurs. This can be easily try/catch'ed in a controlled way. This would be great por the OO API (MsgPack class).
  • Return a specific value when a problem occurs (false, for example) and add a msgpack_last_error() function that returns information about how it was the last unpack operation. This is the behaviour used by the JSON lib on PHP. http://www.php.net//manual/en/function.json-last-error.php

adanlobato avatar Jun 26 '14 10:06 adanlobato

That would be great! :+1:

ghost avatar Jun 30 '14 15:06 ghost

:+1:

rybakit avatar May 07 '15 21:05 rybakit