]> granicus.if.org Git - php/commitdiff
Add test for fixed bug #68992
authorJakub Zelenka <bukka@php.net>
Sun, 28 Aug 2016 12:00:49 +0000 (13:00 +0100)
committerJakub Zelenka <bukka@php.net>
Mon, 29 Aug 2016 13:49:40 +0000 (14:49 +0100)
ext/json/tests/bug68992.phpt [new file with mode: 0644]

diff --git a/ext/json/tests/bug68992.phpt b/ext/json/tests/bug68992.phpt
new file mode 100644 (file)
index 0000000..0fc41ec
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Bug #68992 (json_encode stacks exceptions thrown by JsonSerializable classes)
+--SKIPIF--
+<?php
+if (!extension_loaded('json')) die('skip');
+?>
+--FILE--
+<?php
+
+class MyClass implements JsonSerializable {
+    public function jsonSerialize() {
+           throw new Exception('Not implemented!');
+       }
+}
+$classes = [];
+for($i = 0; $i < 5; $i++) {
+    $classes[] = new MyClass();
+}
+
+try {
+    json_encode($classes);
+} catch(Exception $e) {
+    do {
+           printf("%s (%d) [%s]\n", $e->getMessage(), $e->getCode(), get_class($e));
+       } while ($e = $e->getPrevious());
+}
+?>
+--EXPECT--
+Failed calling MyClass::jsonSerialize() (0) [Exception]
+Not implemented! (0) [Exception]