3v4l.org

run code in 500+ PHP versions simultaneously
<?php try { json_encode("\xB1", JSON_THROW_ON_ERROR); } catch (\Throwable $e) { echo "own throw -> ", get_class($e), ", previous: ", $e->getPrevious() ? get_class($e->getPrevious()) : 'null', "\n"; } class Boom implements JsonSerializable { public function jsonSerialize(): mixed { throw new RuntimeException('thrown inside jsonSerialize()'); } } try { json_encode(new Boom(), JSON_THROW_ON_ERROR); } catch (\Throwable $e) { echo "user throw -> ", get_class($e), ", previous: ", $e->getPrevious() ? get_class($e->getPrevious()) : 'null', "\n"; }
Output for 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
own throw -> JsonException, previous: null user throw -> RuntimeException, previous: null

preferences:
22 ms | 1136 KiB | 8 Q