[HttpFoundation] Fix logic when JsonSerializable is missing
This commit is contained in:
parent
cf4f8325e9
commit
d1fe4153a1
@ -127,30 +127,31 @@ class JsonResponse extends Response
|
|||||||
// but doesn't provide the JsonSerializable interface.
|
// but doesn't provide the JsonSerializable interface.
|
||||||
set_error_handler(function () { return false; });
|
set_error_handler(function () { return false; });
|
||||||
$data = @json_encode($data, $this->encodingOptions);
|
$data = @json_encode($data, $this->encodingOptions);
|
||||||
} else {
|
restore_error_handler();
|
||||||
|
} elseif (\PHP_VERSION_ID < 50500) {
|
||||||
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable
|
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable
|
||||||
// objects in a new exception that needs to be removed.
|
// objects in a new exception that needs to be removed.
|
||||||
// Fortunately, PHP 5.5 and up do not trigger any warning anymore.
|
// Fortunately, PHP 5.5 and up do not trigger any warning anymore.
|
||||||
if (\PHP_VERSION_ID < 50500) {
|
// Clear json_last_error()
|
||||||
// Clear json_last_error()
|
json_encode(null);
|
||||||
json_encode(null);
|
$errorHandler = set_error_handler('var_dump');
|
||||||
$errorHandler = set_error_handler('var_dump');
|
restore_error_handler();
|
||||||
restore_error_handler();
|
set_error_handler(function () use ($errorHandler) {
|
||||||
set_error_handler(function () use ($errorHandler) {
|
if (JSON_ERROR_NONE === json_last_error()) {
|
||||||
if (JSON_ERROR_NONE === json_last_error()) {
|
return $errorHandler && false !== call_user_func_array($errorHandler, func_get_args());
|
||||||
return $errorHandler && false !== call_user_func_array($errorHandler, func_get_args());
|
}
|
||||||
}
|
});
|
||||||
});
|
$data = json_encode($data, $this->encodingOptions);
|
||||||
}
|
restore_error_handler();
|
||||||
|
} else {
|
||||||
$data = json_encode($data, $this->encodingOptions);
|
$data = json_encode($data, $this->encodingOptions);
|
||||||
}
|
}
|
||||||
|
} catch (\Error $e) {
|
||||||
if (\PHP_VERSION_ID < 50500) {
|
if (\PHP_VERSION_ID < 50500 || !interface_exists('JsonSerializable', false)) {
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if (\PHP_VERSION_ID < 50500) {
|
if (\PHP_VERSION_ID < 50500 || !interface_exists('JsonSerializable', false)) {
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
if (interface_exists('JsonSerializable', false) && 'Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
|
if (interface_exists('JsonSerializable', false) && 'Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
|
||||||
|
Reference in New Issue
Block a user