json_encode_exceptions.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Test json_encode() function : JSON_THROW_ON_ERROR flag
  3. --FILE--
  4. <?php
  5. try {
  6. var_dump(json_encode("\x80", JSON_THROW_ON_ERROR));
  7. } catch (JsonException $e) {
  8. var_dump($e);
  9. }
  10. // JSON_PARTIAL_OUTPUT_ON_ERROR is incompatible with exceptions
  11. // So it overrides it for the sake of working with wrappers that add the
  12. // JSON_THROW_ON_ERROR flag
  13. var_dump(json_encode("\x80", JSON_THROW_ON_ERROR | JSON_PARTIAL_OUTPUT_ON_ERROR));
  14. var_dump(json_last_error());
  15. var_dump(json_last_error_msg());
  16. ?>
  17. --EXPECTF--
  18. object(JsonException)#1 (7) {
  19. ["message":protected]=>
  20. string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
  21. ["string":"Exception":private]=>
  22. string(0) ""
  23. ["code":protected]=>
  24. int(5)
  25. ["file":protected]=>
  26. string(%d) "%s"
  27. ["line":protected]=>
  28. int(%d)
  29. ["trace":"Exception":private]=>
  30. array(1) {
  31. [0]=>
  32. array(4) {
  33. ["file"]=>
  34. string(%d) "%s"
  35. ["line"]=>
  36. int(%d)
  37. ["function"]=>
  38. string(11) "json_encode"
  39. ["args"]=>
  40. array(2) {
  41. [0]=>
  42. string(1) "%s"
  43. [1]=>
  44. int(4194304)
  45. }
  46. }
  47. }
  48. ["previous":"Exception":private]=>
  49. NULL
  50. }
  51. string(4) "null"
  52. int(5)
  53. string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"