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