xref: /PHP-7.0/ext/json/tests/bug71835.phpt (revision b49ec681)
1--TEST--
2Bug #71835 (json_encode sometimes incorrectly detects recursion with JsonSerializable)
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip"; ?>
5--FILE--
6<?php
7class SomeClass implements JsonSerializable {
8	public function jsonSerialize() {
9		return [get_object_vars($this)];
10	}
11}
12$class = new SomeClass;
13$arr = [$class];
14var_dump(json_encode($arr));
15
16class SomeClass2 implements JsonSerializable {
17	public function jsonSerialize() {
18		return [(array)$this];
19	}
20}
21$class = new SomeClass2;
22$arr = [$class];
23var_dump(json_encode($arr));
24?>
25--EXPECT--
26string(6) "[[[]]]"
27string(6) "[[[]]]"
28