<?php
class JsonResponse
{
const DEFAULT_ENCODING_OPTIONS = 15;
protected $encodingOptions = self::DEFAULT_ENCODING_OPTIONS;
public function __construct($data = null)
{
$data = json_encode($data, $this->encodingOptions);
}
}
class JsonSerializableObject implements \JsonSerializable
{
public function jsonSerialize()
{
throw new \Exception('This error is expected');
}
}
$serializable = new JsonSerializableObject();
new JsonResponse($serializable);
Deprecated: Return type of JsonSerializableObject::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/nAFVh on line 16
Fatal error: Uncaught Exception: This error is expected in /in/nAFVh:18
Stack trace:
#0 [internal function]: JsonSerializableObject->jsonSerialize()
#1 /in/nAFVh(10): json_encode(Object(JsonSerializableObject), 15)
#2 /in/nAFVh(23): JsonResponse->__construct(Object(JsonSerializableObject))
#3 {main}
thrown in /in/nAFVh on line 18
Process exited with code 255.
Fatal error: Uncaught Exception: This error is expected in /in/nAFVh:18
Stack trace:
#0 [internal function]: JsonSerializableObject->jsonSerialize()
#1 /in/nAFVh(10): json_encode(Object(JsonSerializableObject), 15)
#2 /in/nAFVh(23): JsonResponse->__construct(Object(JsonSerializableObject))
#3 {main}
thrown in /in/nAFVh on line 18
Process exited with code 255.
Output for 7.0.0 - 7.0.11
Fatal error: Uncaught Exception: This error is expected in /in/nAFVh:18
Stack trace:
#0 [internal function]: JsonSerializableObject->jsonSerialize()
#1 /in/nAFVh(10): json_encode(Object(JsonSerializableObject), 15)
#2 /in/nAFVh(23): JsonResponse->__construct(Object(JsonSerializableObject))
#3 {main}
Next Exception: Failed calling JsonSerializableObject::jsonSerialize() in /in/nAFVh:10
Stack trace:
#0 /in/nAFVh(10): json_encode(Object(JsonSerializableObject), 15)
#1 /in/nAFVh(23): JsonResponse->__construct(Object(JsonSerializableObject))
#2 {main}
thrown in /in/nAFVh on line 10
Process exited with code 255.
Output for 5.6.0 - 5.6.26
Fatal error: Uncaught exception 'Exception' with message 'This error is expected' in /in/nAFVh:18
Stack trace:
#0 [internal function]: JsonSerializableObject->jsonSerialize()
#1 /in/nAFVh(10): json_encode(Object(JsonSerializableObject), 15)
#2 /in/nAFVh(23): JsonResponse->__construct(Object(JsonSerializableObject))
#3 {main}
Next exception 'Exception' with message 'Failed calling JsonSerializableObject::jsonSerialize()' in /in/nAFVh:10
Stack trace:
#0 /in/nAFVh(0): json_encode()
#1 /in/nAFVh(23): JsonResponse->__construct(Object(JsonSerializableObject))
#2 {main}
thrown in /in/nAFVh on line 10
Process exited with code 255.