3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 8.1.0 - 8.1.2
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.
Output for 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.27, 8.0.0 - 8.0.15
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.

preferences:
38.7 ms | 465 KiB | 5 Q