xref: /PHP-8.3/ext/json/tests/bug68992.phpt (revision 5beba0b0)
1--TEST--
2Bug #68992 (json_encode stacks exceptions thrown by JsonSerializable classes)
3--FILE--
4<?php
5
6class MyClass implements JsonSerializable {
7    public function jsonSerialize(): mixed {
8        throw new Exception('Not implemented!');
9    }
10}
11$classes = [];
12for($i = 0; $i < 5; $i++) {
13    $classes[] = new MyClass();
14}
15
16try {
17    json_encode($classes);
18} catch(Exception $e) {
19    do {
20        printf("%s (%d) [%s]\n", $e->getMessage(), $e->getCode(), get_class($e));
21    } while ($e = $e->getPrevious());
22}
23?>
24--EXPECT--
25Not implemented! (0) [Exception]
26