xref: /PHP-7.3/ext/json/tests/bug61978.phpt (revision ded3d984)
1--TEST--
2Bug #61978 (Object recursion not detected for classes that implement JsonSerializable)
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip"; ?>
5--FILE--
6<?php
7
8class JsonTest1 {
9	public $test;
10	public $me;
11	public function __construct() {
12		$this->test = '123';
13		$this->me  = $this;
14	}
15}
16
17class JsonTest2 implements JsonSerializable {
18	public $test;
19	public function __construct() {
20		$this->test = '123';
21	}
22	public function jsonSerialize() {
23		return array(
24			'test' => $this->test,
25			'me'   => $this
26		);
27	}
28}
29
30
31$obj1 = new JsonTest1();
32var_dump(json_encode($obj1, JSON_PARTIAL_OUTPUT_ON_ERROR));
33
34echo "==\n";
35
36$obj2 = new JsonTest2();
37var_dump(json_encode($obj2, JSON_PARTIAL_OUTPUT_ON_ERROR));
38
39?>
40--EXPECT--
41string(24) "{"test":"123","me":null}"
42==
43string(24) "{"test":"123","me":null}"
44