xref: /PHP-5.4/ext/json/tests/bug61978.phpt (revision b7903f97)
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));
33
34echo "\n==\n";
35
36$obj2 = new JsonTest2();
37var_dump(json_encode($obj2));
38
39?>
40--EXPECTF--
41Warning: json_encode(): recursion detected in %s on line %d
42string(44) "{"test":"123","me":{"test":"123","me":null}}"
43
44==
45
46Warning: json_encode(): recursion detected in %s on line %d
47string(44) "{"test":"123","me":{"test":"123","me":null}}"
48