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"; }

preferences:
49.75 ms | 481 KiB | 5 Q