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